nerdess
nerdess

Reputation: 10920

PHP DateTime() hours/minutes different but timestamp is the same

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

Upvotes: 0

Views: 635

Answers (2)

user188654
user188654

Reputation:

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.

Upvotes: 1

Ed Heal
Ed Heal

Reputation: 59987

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!

Upvotes: 0

Related Questions