Javascript Date setUTCHours(hours) sets the UTC date's hours.
dateObj.setUTCHours(hoursValue[, minutesValue[, secondsValue[, msValue]]])
hoursValue
- An integer between 0 and 23, representing the hour.minutesValue
- Optional. An integer between 0 and 59, representing the minutes.secondsValue
- Optional. An integer between 0 and 59, representing the seconds. If you specify the secondsValue
parameter, you must also specify the minutesValue
.msValue
- Optional. A number between 0 and 999, representing the milliseconds. If you specify the msValue
parameter, you must also specify the minutesValue
and secondsValue
.The number of milliseconds between January 1, 1970 00:00:00 UTC and the updated date.
If a parameter is outside of the expected range, setUTCHours()
updates the date accordingly.
For example, if you use 100 for secondsValue
, the minutes will be incremented by 1, and 40 will be used for seconds.
Setting the hours to a number greater than 23 also increments the day of the month.
var d = new Date(); console.log(d);//from w w w . ja va 2s . co m d.setUTCHours(8); console.log(d);
Set the time to 15:35:01 UTC time
var d = new Date(); d.setUTCHours(15, 35, 1);//from w w w . j av a2s. com console.log(d);
Set the time to 48 hours ago, using UTC methods:
var d = new Date(); d.setUTCHours(d.getUTCHours() - 48);/* ww w. ja v a 2 s. c o m*/ console.log(d);