tastro Posted March 26, 2012 Share Posted March 26, 2012 how to get the current UTC / GMT date? javascript in php i use gmdate() but i can't find a function here... or can't figure it out how to use it. i found this one: Date.UTC() but it doesn't work for me... no idea why... please help. Quote Link to comment https://forums.phpfreaks.com/topic/259752-how-to-get-the-current-utc-gmt-date-javascript/ Share on other sites More sharing options...
danny_woo Posted March 27, 2012 Share Posted March 27, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259752-how-to-get-the-current-utc-gmt-date-javascript/#findComment-1331407 Share on other sites More sharing options...
nogray Posted March 27, 2012 Share Posted March 27, 2012 Date.UTC requires the year, month and date to work. e.g. var d = Date.UTC(2012, 2, 26); You can also search for getUTCDate, getUTCMonth, getUTCFullYear, etc... Quote Link to comment https://forums.phpfreaks.com/topic/259752-how-to-get-the-current-utc-gmt-date-javascript/#findComment-1331437 Share on other sites More sharing options...
rythemton Posted March 28, 2012 Share Posted March 28, 2012 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()); Quote Link to comment https://forums.phpfreaks.com/topic/259752-how-to-get-the-current-utc-gmt-date-javascript/#findComment-1332051 Share on other sites More sharing options...
tastro Posted March 28, 2012 Author Share Posted March 28, 2012 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. ... Quote Link to comment https://forums.phpfreaks.com/topic/259752-how-to-get-the-current-utc-gmt-date-javascript/#findComment-1332071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.