码迷,mamicode.com
首页 > 其他好文 > 详细

输出日期时间

时间:2017-11-18 16:03:11      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:var   type   cti   head   document   rip   mon   nbsp   new   

1、html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>输出日期时间</title>
</head>
<body>
<h1>当前日期时间</h1>
<div  id="content"></div>
<script src="Date.js"></script>
</body>
</html>
2、js
// JavaScript Document
var t=null;
t=setTimeout(beg,1000)
function beg(){
clearTimeout(t);
var now=new Date();
var year=now.getFullYear();
var month=now.getMonth()+1;
var date=now.getDate();
var array=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六 ");
var i=now.getDay();
var hour=now.getHours();
if (hour<10) {
	hour="0"+hour;
}
var minute=now.getMinutes();
if (minute<10) {
	minute="0"+minute;
}
var second=now.getSeconds();
if (second<10) {
	second="0"+second;
}
var msg=‘<h2>日期时间</h2><p>‘+hour+‘:‘+minute+‘:‘+second+‘<br>‘+year+‘/‘+month+‘/‘+date+‘ ‘+array[i]+‘</p>‘;
var el1=document.getElementById("content");
el1.innerHTML=msg;
t=setTimeout(beg,1000);
}

  

输出日期时间

标签:var   type   cti   head   document   rip   mon   nbsp   new   

原文地址:http://www.cnblogs.com/qfdy123/p/7856842.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!