note 119152 deleted from datetime.gettimestamp by cmb
| From: | cmb@php.net | Date: | Sun, 05 Jan 2020 08:50:56 +0000 |
| Subject: | note 119152 deleted from datetime.gettimestamp by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213781@lists.php.net to get a copy of this message | ||
Note Submitter: miguelmuscat93 at gmail dot com
----
Note that getTimestamp() does not return the UTC timestamp. It returns the timestamp relative to the
set timezone, or the default server timezone. This also applies to dates in timezones with Daylight
Savings.
<?php
// 11th March 2016 @ 11:00 UTC has timestamp: 1457694000
$d1 = new DateTime('2016-03-11 11:00:00', new DateTimeZone('Europe/Rome'));
$t1 = $d1->getTimestamp();
// 11th April 2016 @ 11:00 UTC has timestamp: 1460372400
$d2 = new DateTime('2016-04-11 11:00:00', new DateTimeZone('Europe/Rome'));
$t2 = $d2->getTimestamp();
printf("11 March: %d (diff = %d less)\n", $t1, 1457694000 - $t1);
printf("11 April: %d (diff = %d less)", $t2, 1460372400 - $t2);
// Prints:
// 1457690400 (diff = 3600)
// 1460365200 (diff = 7200)