Home  >  Article  >  Web Front-end  >  How to display today’s date in real time using javascript_javascript skills

How to display today’s date in real time using javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:58:091433browse

The example in this article describes the method of using javascript to display the current day's date in real time. Share it with everyone for your reference. The specific implementation method is as follows:

<!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>

The operation effect is as shown below:

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn