本文共 765 字,大约阅读时间需要 2 分钟。
To get the current time in JavaScript, we need to use three library functions of Date class,
要获取JavaScript中的当前时间 ,我们需要使用Date类的三个库函数,
– It returns current hours
–返回当前时间
– It returns current minutes
–返回当前分钟
– It returns current seconds
–返回当前秒数
Note: To call these functions, we need to create an object to the Date class using .
注意:要调用这些函数,我们需要使用为Date类创建一个对象。
Examples:
例子:
Date class constructor: var dt = new Date(); Function calls: dt.getHours(); dt.getMinues(); dt.getSeconds(); Output: 20 12 35
JavaScript code to get the current time in Hours24: Minutes: Seconds format
JavaScript代码以Hours24:Minutes:Seconds格式获取当前时间
JavaScipt Example
Output
输出量
Current time is= 20:12:35
翻译自:
转载地址:http://akxzd.baihongyu.com/