Reputation: 73175
I'm trying to synchronize the timezone between a PHP script and some JavaScript code.
I want a PHP function that returns a timestamp in UTC. Does gmmktime() do that?
On the JavaScript side, I have:
var real_date = new Date();
real_date -= real_date.getTimezoneOffset() * 60000;
real_date /= 1000;
Does this convert the timestamp to UTC?
Upvotes: 1
Views: 814
Reputation: 526573
Just time()
will do what you want. If you want an arbitrary timestamp, instead of the current time, then gmmktime
will do that, yes.
Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
http://www.php.net/manual/en/function.time.php
You can use the .UTC()
method of a Date object to get # of milliseconds in UTC. However, your current solution should also work, if you're starting with a timestamp.
Upvotes: 5