JavaScript setHours () method
Definition and Usage
setHours () method is used to set the time specified hours field.
This method can be used to set the minutes, seconds and milliseconds.
Browser Support
All major browsers support setHours () method
grammar
Date .setHours( hour,min,sec,millisec )
Parameter Value
参数 | 描述 |
---|---|
hour | 必需。
表示小时的数值,介于 0(午夜) ~ 23(晚上11点) 之间,以本地时间计(下同)。
|
min | 可选。表示分钟的数值。
,介于 0 ~ 59 之间。在 EMCAScript 标准化之前,不支持该参数:
|
sec | 可选。表示秒的数值
,介于 0 ~ 59 之间。在 EMCAScript 标准化之前,不支持该参数:
|
millisec | 可选。表示毫秒的数值。
介于 0 ~ 999之间。在 EMCAScript 标准化之前,不支持该参数:
|
return value
类型 | 描述 |
---|---|
Number | Milliseconds between the date object and midnight January 1 1970 |
technical details
JavaScript version: | 1.0 |
---|
More examples
Examples
In this example, we will setHours () method set the time to 15:35:01:
var d = new Date();
d.setHours(15,35,1);
d.setHours(15,35,1);
d output:
try it"
Examples
Set time of 48 hours ago:
var d = new Date();
d.setHours(d.getHours()-48);
d.setHours(d.getHours()-48);
d output:
try it"