JS显示实时日期时分秒的脚本

发布时间:2020-11-22编辑:脚本学堂
小编来介绍一下js实时显示当天日期的脚本,可实时显示当前日期及星期的功能,非常简单实用。

直接上实例 JSt实时显示当天日期的脚本


 

<!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>js显示时间</title>
 </head> 
<body>
 <div id="divBottom"></div>
 <script type="text/javascript"> 
//获取当天日期 
function date() {  
 var date=new Date();   
var year=date.getFullYear();  
 var month=date.getMonth()+1;  
 var day=date.getDate();  
 var hour="00"+date.getHours();    
 hour=hour.substr(hour.length-2);   
var minute="00"+date.getMinutes();   
  minute=minute.substr(minute.length-2); 
  var second="00"+date.getSeconds();   
  second=second.substr(second.length-2);  
 var week=date.getDay(); 
  switch(week)   {     case 1:week="星期一 ";break;     case 2:week="星期二 ";break;     case 3:week="星期三 ";break;     case 4:week="星期四 ";break;     case 5:week="星期五 ";break;     case 6:week="星期六 ";break;     case 0:week="星期日 ";break;     default:week="";break;   }  
 document.getElementById("divBottom").innerHTML=year+"年"+month+"月"+day+"日"+" "+hour+":"+minute+":"+second+" "+week; } setInterval("date()",1000);
 </script>
 </body>
 </html>