Javascript Date getUTCHours()
returns the hours as a number between 0 and 23 according to universal time.
An integer number, between 0 and 23, representing the hours in the given date according to universal time.
// current date/*w w w .ja v a2 s . c o m*/ let date = new Date(); // the hour in UTC+0 time zone console.log( date.getUTCHours() );
Return the UTC hour from a specific date and time:
var d = new Date("July 21, 2010 01:15:00"); var n = d.getUTCHours(); console.log(n);/*from www . j ava 2 s. c o m*/
Using getUTCHours()
, getUTCMinutes()
, and getUTCSeconds()
to display the universal time:
function addZero(i) { if (i < 10) { i = "0" + i;// w w w. ja v a 2s . com } return i; } var d = new Date(); var h = addZero(d.getUTCHours()); var m = addZero(d.getUTCMinutes()); var s = addZero(d.getUTCSeconds()); console.log(h + ":" + m + ":" + s);