This article describes how JS can simply obtain and display the current time. Share it for your reference, as follows:
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>Current time</title></head><body> <script>var now = new Date();var year = now.getFullYear(); //year var month = now.getMonth() + 1; //month var day = now.getDate(); //day var hh = now.getHours(); //time var mm = now.getMinutes(); //平 var clock = year + "-";if (month < 10)clock += "0";clock += month + "-";if (day < 10)clock += "0";clock += day + " ";if (hh < 10)clock += "0";clock += hh + ":";if (mm < 10)clock += '0';clock += mm;document.write(clock);</script></body></html>
PS: Friends who are interested in JavaScript time and date operations can also refer to the online tools of this site:
Unix timestamp conversion tool:
http://tools.VeVB.COM/code/unixtime
Online time inquiry around the world:
http://tools.VeVB.COM/zhuanhuanqi/worldtime
Online Perpetual Calendar:
http://tools.VeVB.COM/bianmin/wannianli
Web Perpetual Calendar:
http://tools.VeVB.COM/bianmin/webwannianli
For more information about JavaScript, please check this site's special topics: "Summary of JavaScript Time and Date Operation Skills", "Summary of JavaScript Switching Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Data Structures and Algorithm Skills", "Summary of JavaScript Traversal Algorithm and Skills" and "Summary of JavaScript Mathematical Operation Usage"
I hope this article will be helpful to everyone's JavaScript programming.