I used strtotime($datetime)
in PHP to convert textual datetime description into Unix timestamp (see code below).
$datetime = '2012-04-17 00:00:00';
$timestamp = strtotime($datetime);
However, the result of $timestamp
in Time zone (London) was 1334617200 and in Time zone (Beijing) it was 1334620800.
Can anyone explain me why this happened? Is the result of strtotime()
changed based on the timezone?
Thanks in advance!
From the documentation:
Each parameter of this function uses the default time zone unless a time zone is specified in that parameter. Be careful not to use different time zones in each parameter unless that is intended. See date_default_timezone_get() on the various ways to define the default time zone.
So yes, it is based on the time zone unless you specify a specific timezone in $datetime
Yes, that is correct. Timezone is taken into account.
See also: PHP - strtotime, specify timezone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With