0

I am trying to get a timestamp for both the current New York and London date/time.

date_default_timezone_set('America/New_York');
$dtNY = new DateTime();
echo 'New York';
echo date('m-d-Y H:i:s', $dtNY->getTimestamp());
echo $dtNY->getTimestamp(); 
echo 'London';
date_default_timezone_set('Europe/London');
$dtLondon = new DateTime();
echo date('m-d-Y H:i:s', $dtLondon->getTimestamp());
echo $dtLondon->getTimestamp();

The result of above code is

New York 03-30-2012 08:32:49 1333110769

London 03-30-2012 13:32:49 1333110769

Why does above code give me totally identical timestamps but different dates?!? this is not logical :-s

nerdess
  • 10,051
  • 10
  • 45
  • 55
  • 3
    Because at any given moment (i.e. what a timestamp represents) the local time in NY is not the same as the local time in London. It's perfectly logical. Right now NY is at GMT-4 and London at GMT+1, hence the 5-hour observed local time difference. – Jon Mar 30 '12 at 12:45
  • so at any moment time() will give me the same timestamp no matter if i run it on a server in the UK, a sever in London or a server in Siberia? – nerdess Mar 30 '12 at 13:30
  • Assuming all servers have set up their clock correctly and that the system administrators have selected the correct timezone for their physical location, yes. There is also a good amount of configuration where an outdated or incorrect setup will result in differences, but that's not what you are asking. – Jon Mar 30 '12 at 13:31

2 Answers2

1

The actual answer to your question is that the UNIX timestamp is always represented in UTC time however when you choose to convert that timestamp into local time the chosen time zone is taken into account while performing the conversion.

0

Time stamps use UTC. The same everywhere on the planet. But local times differ. i.e. You would not like to have lunch the same time as we do, you would prefer breakfast in New York whilst in Edinburgh we are having lunch!

Ed Heal
  • 59,252
  • 17
  • 87
  • 127