javascript
在JavaScript中以Hours24:Minutes:Seconds格式获取当前时间
使用JavaScript獲取當(dāng)前時間 (Getting current time in JavaScript)
To get the current time in JavaScript, we need to use three library functions of Date class,
要獲取JavaScript中的當(dāng)前時間 ,我們需要使用Date類的三個庫函數(shù),
Date getHours() Method – It returns current hours
Date getHours()方法 –返回當(dāng)前時間
Date getMinutes() Method – It returns current minutes
Date getMinutes()方法 –返回當(dāng)前分鐘
Date getSeconds() Method – It returns current seconds
Date getSeconds()方法 –返回當(dāng)前秒數(shù)
Note: To call these functions, we need to create an object to the Date class using Date class constructor.
注意:要調(diào)用這些函數(shù),我們需要使用Date類的構(gòu)造函數(shù)為Date類創(chuàng)建一個對象。
Examples:
例子:
Date class constructor:var dt = new Date();Function calls:dt.getHours();dt.getMinues();dt.getSeconds();Output:201235JavaScript code to get the current time in Hours24: Minutes: Seconds format
JavaScript代碼以Hours24:Minutes:Seconds格式獲取當(dāng)前時間
<html> <head><title>JavaScipt Example</title></head><body> <script>var dt = new Date(); //Date constructor var hh = dt.getHours();var mm = dt.getMinutes();var ss = dt.getSeconds();//printing timedocument.write("Current time is= " + hh + ":" + mm + ":" + ss + "<br>"); </script> </body> </html>Output
輸出量
Current time is= 20:12:35翻譯自: https://www.includehelp.com/code-snippets/get-current-time-in-hours24-minutes-seconds-format-in-javascript.aspx
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的在JavaScript中以Hours24:Minutes:Seconds格式获取当前时间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php fpm www.conf,PHP
- 下一篇: c语言指针++_C ++此指针| 查找输