Home Web Front-end JS Tutorial 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

May 16, 2016 pm 03:58 PM
javascript real-time display date

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>
Copy after login

The operation effect is as shown below:

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

Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to search previous Weibo by date on Weibo_How to search previous Weibo by date on Weibo How to search previous Weibo by date on Weibo_How to search previous Weibo by date on Weibo Mar 30, 2024 pm 07:26 PM

How to search previous Weibo by date on Weibo_How to search previous Weibo by date on Weibo

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to implement an online speech recognition system using WebSocket and JavaScript

How to remove the date that appears automatically when printing from PPT handouts How to remove the date that appears automatically when printing from PPT handouts Mar 26, 2024 pm 08:16 PM

How to remove the date that appears automatically when printing from PPT handouts

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

How to display date and seconds in the top bar of Ubuntu 17.10? How to display date and seconds in the top bar of Ubuntu 17.10? Jan 08, 2024 am 10:41 AM

How to display date and seconds in the top bar of Ubuntu 17.10?

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to implement an online reservation system using WebSocket and JavaScript

How to change the date into a pound sign in Excel How to change the date into a pound sign in Excel Mar 20, 2024 am 11:46 AM

How to change the date into a pound sign in Excel

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

How to use JavaScript and WebSocket to implement a real-time online ordering system

See all articles