Posted in Javascript onAugust 02, 2016
本文实例讲述了JavaScript简单获取系统当前时间的方法。分享给大家供大家参考,具体如下:
运行效果截图如下:
具体代码如下:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>获取当前时间</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>
JavaScript简单获取系统当前时间完整示例
- Author -
Quber声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@