HTML5网页设计

时间日期

显示当前时间JS代码

时间:2016-02-25 17:09来源:未知作者:user点击:
使用前先导入jQuery库文件。JS代码:

使用前先导入jQuery库文件。

JS代码

$(function(){
	setInterval(function(){
		$("#now-time").text(currentTime);
	},1000);
});
function currentTime(){
	var nDate = new Date(),str = '';
	var year=nDate.getFullYear();
	var month=nDate.getMonth()+1;
	var day=nDate.getDate();
	var week=nDate.getDay();
	var h=nDate.getHours();
	var mins=nDate.getMinutes();
	var s=nDate.getSeconds();
	if(month<10) month="0" + month
	if(day<10) month="0" + day
	if(h<10) h="0" + h
	if(mins<10) mins="0" + mins
	if(s<10) s="0" + s
	// var shows= year + "-" + month + "-" + day + " " + h + ":" + mins +  ":" + s + " " + w_array[week];
	var shows= h + ":" + mins +  ":" + s;
	return shows;
}

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>显示当前时间JS代码</title>
	<script src="http://www.shejicool.com/demo/jquery.min.js"></script>
	<style>
		#now-time {padding: 100px;text-align: center;font-size: 20px;}
	</style>
</head>
<body>
	<div id="now-time"></div>
<script>
$(function(){
	setInterval(function(){
		$("#now-time").text(currentTime);
	},1000);
});
function currentTime(){
	var nDate = new Date(),str = '';
	var year=nDate.getFullYear();
	var month=nDate.getMonth()+1;
	var day=nDate.getDate();
	var week=nDate.getDay();
	var h=nDate.getHours();
	var mins=nDate.getMinutes();
	var s=nDate.getSeconds();
	if(month<10) month="0" + month
	if(day<10) month="0" + day
	if(h<10) h="0" + h
	if(mins<10) mins="0" + mins
	if(s<10) s="0" + s
	// var shows= year + "-" + month + "-" + day + " " + h + ":" + mins +  ":" + s + " " + w_array[week];
	var shows= h + ":" + mins +  ":" + s;
	return shows;
}
</script>
</body>
</html>
上一篇:上一篇:jQuery版网页倒计时动态效果 上一篇:下一篇:Javascript时间戳转日期时间方法
阅完本篇文章?您还可以: 收藏本文 文章挑错 朋友推荐