This article describes the method of JavaScript to simply obtain the current time of the system. Share it for your reference, as follows:
The screenshot of the running effect is as follows:
The specific code is as follows:
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Get the current time</title> <script> function getCurrentDate() { var dtCur = new Date(); var yearCur = dtCur.getFullYear(); var monCur = dtCur.getMonth() + 1; var dayCur = dtCur.getDate(); var hCur = dtCur.getHours(); var mCur = dtCur.getMinutes(); var sCur = dtCur.getSeconds(); var timeCur = yearCur + "-" + (monCur < 10 ? "0" + monCur : monCur) + "-" + (dayCur < 10 ? "0" + dayCur : dayCur) + " " + (hCur < 10 ? "0" + hCur : hCur) + ":" + (mCur < 10 ? "0" + mCur : mCur) + ":" + (sCur < 10 ? "0" + sCur : sCur); return timeCur; } </script></head><body> <script> var nowstr=getCurrentDate(); document.write(nowstr); </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.