The CMS I'm using allows me to access the user's time offset from UTC/GMT time. So, if the user has set their timezone to EST, then this offset will be "-5."
What I'm doing right now when I need to display the current time is something like:
date('M j Y h:i A', time() + $offset*3600)
This works, except when daylight savings time is in affect for the user, then it is an hour behind.
So, my question is, how I can determine whether a given time offset (like "-5") needs to have an hour added to it?
An offset is the number of hours or minutes a certain time zone is ahead of or behind GMT**. A time zone's offset can change throughout the year because of Daylight Saving Time.
Daylight Saving Time - When do we change our clocks? Most of the United States begins Daylight Saving Time at 2:00 a.m. on the second Sunday in March and reverts to standard time on the first Sunday in November.
Daylight Saving Time has never been used here. Clocks do not change in UTC, Time Zone. There is no previous DST change in Time Zone.
Definition and Usage. getTimezoneOffset() returns the difference between UTC time and local time. getTimezoneOffset() returns the difference in minutes. For example, if your time zone is GMT+2, -120 will be returned.
http://php.net/manual/en/function.date.php
I (capital i) | Whether or not the date is in daylight saving time | 1 if Daylight Saving Time, 0 otherwise.
Does this help?
You cant derive this from the offset alone because the offset applies to the whole latitude and countries on that do not have uniform DST in effect. For instance in Australia, Daylight Saving Time is not observed in Queensland, the Northern Territory or Western Australia but everywhere else. You'd have to geolocate your users and then check with PHP's DateTimeZone API whether there is DST in that country.
Also see How to automatically detect user's 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