javascript实时显示当天日期的方法
人气:1本文实例讲述了javascript实时显示当天日期的方法。分享给大家供大家参考。具体实现方法如下:
<!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>
运行效果如下图所示:
希望本文所述对大家的javascript程序设计有所帮助。
加载全部内容