本文共 907 字,大约阅读时间需要 3 分钟。
setHours() method is a Date class method, it is used to set the hour to the Date object with a valid hour value (between 00 to 23).
setHours()方法是Date类方法,用于将小时设置为具有有效小时值(介于00到23之间)的Date对象。
Note: Hour value larger than the 23 will be truncated from the starting hour value (0), for example, we are going to set 26 as an hour value, it will be truncated as 2.
注意:大于23的小时值将从开始的小时值(0)开始被截断,例如,我们将26设置为小时值,它将被截断为2。
Syntax:
句法:
var dt = new Date(); dt.setHours(hour);
Examples:
例子:
Input/Date class object declaration: var dt = new Date(); Function call to set the hour: dt.setHours(16); Function call to get the hour: dt.getHours(); Output: 16
JavaScript code to demonstrate an example of Date.setHours() method
JavaScript代码演示Date.setHours()方法的示例
JavaScipt Example
Output
输出量
hour: 19hour: 16hour: 2
Reference:
参考:
翻译自:
转载地址:http://dfazd.baihongyu.com/