Jump to content

how to get the current UTC / GMT date? javascript


tastro

Recommended Posts

I have the same issue my friend.

 

I'm having problems with DST and offsetting the time, I posted on Friday and after 40 something views I'm still no better off.

 

I'll be watching this topic with interest.

 

Best of luck mate, I hope someone can help us out.

Got this from http://stackoverflow.com/questions/948532/how-do-you-convert-a-javascript-date-to-utc

var now = new Date(); 
var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),  now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());

i solved my problem and all is working fine now.

 

i hope that this will help some people.

 

also first i had it like this:

 

// months must be -1 !!! because it counts from 0 to 11 and not from 1 to 12

var utcdate = new Date.UTC(2011,2,15);

 

and it didn't work because of the "new" before Date.UTC which i didn't knew that it shouldn't be there, because it has to be if you use only Date and not Date.UTC

 

and now it's working perfect like this:

 

var utcdate = Date.UTC(2011,2,15);

 

and you get the time / date in miliseconds i think... you have to divide the time you get with 1000 to get seconds. and then with 60 to get minutes and then with 60 once more to get hours and then with 24 to get days, etc. ...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.