The getUTCHours() method returns the hour ranged from 0 to 23 of date object, according to universal time.
The getUTCHours() method returns the hour ranged from 0 to 23 of date object, according to universal time.
UTC time is the same as GMT time.
Date.getUTCHours()
None
A Number, from 0 to 23, representing the hour
Return the hour, according to universal time:
//display the hour, according to UTC. var d = new Date(); var n = d.getUTCHours(); console.log(n);/*from w w w .java 2 s . c o m*/ //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);
Using getUTCHours(), getUTCMinutes(), and getUTCSeconds() to display the universal time:
//display the UTC time. function addZero(i) { if (i < 10) { i = "0" + i; }//from w ww .j a v a 2 s. co m 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);