0

I am using php and receiving a timestamp from the server which is in GMT time. How do I update the timestamp to be in the user's timezone (not the server's timezone) or to get the difference between the user's timezone and GMT?

I have already tried

date("Z");

but it returned 0

L. Young
  • 163
  • 3
  • 7
  • 24
  • Use `$dif = gmdate('T') - time();` which should tell you the difference in milliseconds. – Ismael Miguel Feb 02 '15 at 17:17
  • 1
    possible duplicate of [Determining a web user's time zone](http://stackoverflow.com/questions/13/determining-a-web-users-time-zone) – β.εηοιτ.βε Feb 02 '15 at 17:18
  • @IsmaelMiguel I think the format may be different because when add this to me unix timestamp i get a differenct of around 20 days... `$newtime = gmdate('T') - time(); $unixStartDate = $unixStartDate + $newtime; $unixStartDate = $unixStartDate/1000; $matchDate = gmdate("d-m-Y", $unixStartDate); $matchTime = gmdate("H:i", $unixStartDate);` – L. Young Feb 02 '15 at 17:31
  • What's the content of those variables? – Ismael Miguel Feb 02 '15 at 18:22

1 Answers1

3

You do not have access to that information.

The easiest way may be to have JavaScript provide it:

var offset = (new Date()).getTimezoneOffset();
// use AJAX to send offset to server

Note that offset will be in minutes, and relative to UTC.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • but I am getting a timestamp value from the server which I am converting to a date and tiem value in this way `$unixStartDate = $unixStartDate/1000; $matchDate = gmdate("d-m-Y", $unixStartDate); $matchTime = gmdate("H:i", $unixStartDate);` How can I use the JS value to update the unix php value before converting? Sorry if this is a stupid question I only just started using php – L. Young Feb 02 '15 at 17:24
  • 1
    @L.Young Have a look at some of the examples in the duplicate question mentioned above. Basically, you need to use JS to send this in a hidden field, an AJAX request, or a cookie, which PHP can then read. – IMSoP Feb 02 '15 at 17:46