———————
PHP timezones example
written by Simon Hutchison - http://www.econfirm.com.au/
———————
date_default_timezone_set("Australia/Sydney")
Sun, 02 Mar 2008 14:57:11 +1100
date_default_timezone_set("Australia/Perth")
Sun, 02 Mar 2008 12:57:11 +0900
———————
The comments in this example assumes server is Sydney time.
———————
Demonstrating that timezone is not important for mktime(), date(”U”) and time(). Get GMT 0. Uses the server time to adjust to GMT 0 so need to ensure server time is correct for these functions to be accurate.
date_default_timezone_set("Australia/Perth")
mktime() : 1204430231
date("u") : 1204430231
time() : 1204430231
date_default_timezone_set("Australia/Sydney")
mktime() : 1204430231
date("u") : 1204430231
time() : 1204430231
———————
Now that we know this we can use these functions to compare to other GMT 0 adjusted times.
Demonstrating that timezone is critical for date(”date format string”) and strtotime(”date string”) because it takes a user string from anywhere in the world!!
date_default_timezone_set("Australia/Sydney")
The next values of time() and strtotime will be very close (within a second) because both the default timezone and the server time is Sydney.
strtotime(): 1204426991
time() : 1204430231 just after the strtotime converted date/time
date("r") : Sun, 02 Mar 2008 14:57:11 +1100x
date_default_timezone_set("Australia/Perth")
The next values of time() and strtotime will be about two hours apart because the default timezone is Perth and the server time is Sydney.
strtotime(): 1204434191
time() : 1204430231 about two hours before the strtotime converted date/time for Perth time. (Remember the server is in Sydney)
date("r") : Sun, 02 Mar 2008 12:57:11 +0900
This means that mktime() can be used to compare any normalised (strtotime with timezone set) time Normalise all incoming user dates using strtotime with date_default_timezone_set set correctly.
———————