Why does strtotime give different result in different timezone?

Muhammad Usman picture Muhammad Usman · Sep 3, 2011 · Viewed 10.5k times · Source

I am not sure why strtotime() in PHP returns different result in different timezone even though same date is given as parameter, does anyone know the answer? I also want to know, can I do similar task (converting a datetime to an int to do calculations easily) with another function which gives same result across different timezone?

EDIT:

An example: If I use strtotime('2011-09-19 00:00:00') shouldn't it just return the difference between 'January 1 1970 00:00:00' and '2011-09-19 00:00:00' in seconds ? Why timezone is an issue here? And can I get something which gives just difference without timezone issue?

Answer

masnun picture masnun · Sep 4, 2011

In short: time zone is considered because the Unix Epoch value is considered in GMT.

In broader sense 2011-09-19 00:00:00 comes to Bangladesh almost after 6 hours it is 2011-09-19 00:00:00 in GMT zone. Because of this gap, another 21600 seconds have passed in the GMT zone when the same date appears in BD.

Since the calculation is done in respect to the GMT, you have to add these 21600 seconds to get the actual difference.