PHP Compare DateTimes with Timezone

Viewed 385

I have to use UTC as the default for my entire project.

date_default_timezone_set('UTC');

However, in one instance, I need to be able to compare a DateTime against the current time in London. But it seems that TimeStamps and DateTime comparisons can only compare the UTC value of any DateTime due to the default setting. For instance:

$d = new DateTime();
$t = clone $d;
$t->setTimezone(new DateTimeZone('Europe/London'));

var_dump($t);
{"date":"2017-06-02 15:41:34.000000","timezone_type":3,"timezone":"Europe\/London"}

var_dump($d);
{"date":"2017-06-02 14:41:34.000000","timezone_type":3,"timezone":"UTC"}

The hours show a 1 hour difference which is correct. But:

var_dump($d == $t);
true
var_dump($d->getTimeStamp() == $t->getTimeStamp());
true

I want to show the the London time ($t) as greater than UTC time ($d).

Is there any way to do that?

2 Answers
Related