本文實例講述了JS簡單獲取及顯示當前時間的方法。分享給大家供大家參考,具體如下:
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>當前時間</title></head><body> <script>var now = new Date();var year = now.getFullYear(); //年var month = now.getMonth() + 1; //月var day = now.getDate(); //日var hh = now.getHours(); //時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:對JavaScript時間與日期操作感興趣的朋友還可以參考本站在線工具:
Unix時間戳(timestamp)轉換工具:
http://tools.VeVB.COm/code/unixtime
在線世界各地時間查詢:
http://tools.VeVB.COm/zhuanhuanqi/worldtime
在線萬年歷日歷:
http://tools.VeVB.COm/bianmin/wannianli
網頁萬年歷日歷:
http://tools.VeVB.COm/bianmin/webwannianli
更多關于JavaScript相關內容可查看本站專題:《JavaScript時間與日期操作技巧總結》、《JavaScript切換特效與技巧總結》、《JavaScript查找算法技巧總結》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調試技巧總結》、《JavaScript數據結構與算法技巧總結》、《JavaScript遍歷算法與技巧總結》及《JavaScript數學運算用法總結》
希望本文所述對大家JavaScript程序設計有所幫助。
新聞熱點
疑難解答