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
  • 6,050
  • 13
  • 68
  • 106
  • Also see [How do I get a UTC timestamp in JavaScript?](http://stackoverflow.com/questions/9756120/how-do-i-get-a-utc-timestamp-in-javascript) – TylerH Apr 12 '15 at 18:53
  • @TylerH, I'm not sure if this is a duplicate. I know how to get a Unix Timestamp. I'm not sure you understood my question. Edited question – Newtt Apr 12 '15 at 18:56
  • Why do you get the minutes? – user4759923 Apr 12 '15 at 18:59
  • @Newtt If your code is working and you are looking for improvements, CodeReview.StackExchange is the place to ask your question. – TylerH Apr 13 '15 at 03:30

2 Answers2

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

Like this?

Pataar
  • 651
  • 8
  • 14
0

The one works well:

var UTCTime= (new Date()).toUTCString();
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331