-2

Here it's said:

A timestamp is the number of seconds since Midnight 1 January 1970, GMT. It doesn't matter where you are in the world, a given timestamp represents the exact same moment in time, regardless of time zones.

So I tried that:

$date_str="2010-01-10 12:00";

$TimeZone_toronto=new DateTimeZone('America/Toronto');
$date_obj_toronto=new DateTime($date_str, $TimeZone_toronto);
$date_time_stamp_toronto=$date_obj_toronto->format('U'); 

$TimeZone_GMT=new DateTimeZone('GMT');
$date_obj_GMT=new DateTime($date_str, $TimeZone_GMT);
$date_time_stamp_GMT=$date_obj_GMT->format('U');

Based on the quote above: should be $date_time_stamp_toronto==$date_time_stamp_GMT

But here are the values:

$date_time_stamp_toronto = 1263142800
$date_time_stamp_GMT     = 1263124800

So => $date_time_stamp_toronto!=$date_time_stamp_GMT because:

1263142800!=1263124800

Where is the truth?

Community
  • 1
  • 1
ihtus
  • 2,673
  • 13
  • 40
  • 58
  • 3
    The truth is it works fine http://3v4l.org/Ms108 . Also, don't use GMT, use UTC instead http://uk1.php.net/manual/en/timezones.others.php See the red box halfway down he page. – vascowhite Aug 14 '13 at 14:55
  • 5
    You're missing that `2010-01-10 12:00` in Toronto and `2010-01-10 12:00 GMT` do **not** refer to the same moment in time. – Carsten Aug 14 '13 at 14:58
  • vascowhite: I will get same timestamps as you showed in demi if $date_str="now";.. but what about $date_str="2010-01-10 12:00"; – ihtus Aug 14 '13 at 15:02
  • Why would you think that 12:00 in Toronto = 12:00 GMT? It obviously doesn't. http://3v4l.org/9T7sJ Does that help? – vascowhite Aug 14 '13 at 15:03

1 Answers1

7

"2010-01-10 12:00" in Toronto and Greenwich local time respectively are obviously two very different times with a different timestamp.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • If `2010-01-10 12:00` ***local time*** is different based on the timezone, why isn't `now` (assumingly also local time)? [**DEMO**](http://3v4l.org/fCUv0). – h2ooooooo Aug 14 '13 at 14:59
  • Because ***now*** is whatever time it is ***now*** at that location. 12 o'clock at that location is not *now* and it's 12 o'clock at different times in different parts of the world. Are you expecting "now" to mean "take whatever wall clock time it is now *in my timezone* and use that same number as the wall clock time in a different timezone"? That makes no sense. :) – deceze Aug 14 '13 at 15:00
  • But surely `now` when specifying a timezone ***should*** refer to `now` in **that** timezone, right? – h2ooooooo Aug 14 '13 at 15:01
  • 2010-01-19 12:00 in Toronto is 2010-01-19 16:00 GMT – vascowhite Aug 14 '13 at 15:02
  • @h2o ...yes...?! And "now" in Berlin is a different wall clock time than "now" in Tokyo, yet both have the same UNIX timestamp, because it's *now*. – deceze Aug 14 '13 at 15:03
  • 1
    @deceze Oh wow - I must be half asleep - time to go home because my brain is obviously done for today. Thanks for the ELI5 explanation. – h2ooooooo Aug 14 '13 at 15:03