1

Is it possible for me to get the UTC time of current hour in Javascript?

I've tried the following:

var mins = new Date().getMinutes();
var hours = new Date().getHours();
var hourStamp = new Date().setHours(hours, 0,0,0);
var dates = new Date(hourStamp);

Here dates gives me the Unix Timestamp of the current hour. Is there a better/faster way to do this?

EDIT:

For example: I want the Timestamp for the current hour. So if it's 00:16 am on 12/04/2015, I want the timestamp of 12/04/2015 00:00. And, my method works. My question pertains to if there's a better method of doing the same.

Newtt
  • 5,773
  • 13
  • 63
  • 101

2 Answers2

1
var UTCHour = new Date().getUTCHours();

Like this?

Pataar
  • 631
  • 8
  • 14
0

The one works well:

var UTCTime= (new Date()).toUTCString();
Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319