【在系统首页显示当前时间,模拟时间的行走,1秒钟1秒钟的走。。。。】


<script src="${pageContext.request.contextPath}/ui/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript">
	$(function() {
		// 在页面显示时间
		setInterval(getNowFormatDateMethod, 1000);
	});
	// 时间封装方法
	function getNowFormatDateMethod() {
		$("#nowTime").text(getNowFormatDate());
	}
	// 获取当前时间的工具类
	function getNowFormatDate() {
		var date = new Date();
		var seperator1 = "-";
		var seperator2 = ":";
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		var minutes = date.getMinutes();
		var seconds = date.getSeconds();
		if (month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if (strDate >= 0 && strDate <= 9) {
			strDate = "0" + strDate;
		}
		if (minutes >= 0 && minutes <= 9) {
			minutes = "0" + minutes;
		}
		if (seconds >= 0 && seconds <= 9) {
			seconds = "0" + seconds;
		}
		var currentdate = date.getFullYear() + seperator1 + month + seperator1
				+ strDate + " " + date.getHours() + seperator2
				+ minutes + seperator2 + seconds;
		return currentdate;
	}
</script>

  

 

效果图:

 

posted @ 2017-06-22 17:08  半生戎马,共话桑麻、  阅读(149)  评论(0)    收藏  举报
levels of contents