I want to list for the user, all timezones with their native UTC/GMT offset, regardless of DST
How can I do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I ‘ve come up with this function to do the job:
How it works
The function accepts a timezone and creates two
DateTimeobjects: January 1st 00:00 of the current year and January 1st 00:00 of the next year, both specified in that timezone.It then calculates the DST transitions during this year, and returns the offset for the first transition it finds where DST is not active.
PHP 5.3 is required because of the call to
DateTimeZone::getTransitionswith three parameters. If you want this to work in earlier versions you will have to accept a performance hit, because a whole lot of transitions will be generated by PHP (in this case, you don’t need to bother with creating the$startOfYearand$startOfNextdates).I have also tested this with timezones that do not observe DST (e.g.
Asia/Calcutta) and it works for those as well.To test it: