Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the result of strtotime() changed based on the timezone?

Tags:

php

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!

like image 941
Acubi Avatar asked May 02 '12 15:05

Acubi


2 Answers

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

like image 70
Eric Petroelje Avatar answered Sep 19 '22 20:09

Eric Petroelje


Yes, that is correct. Timezone is taken into account.

See also: PHP - strtotime, specify timezone

like image 20
Brad Avatar answered Sep 22 '22 20:09

Brad