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?
PHP
Just
time()will do what you want. If you want an arbitrary timestamp, instead of the current time, thengmmktimewill do that, yes.http://www.php.net/manual/en/function.time.php
Javascript
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.