Allow user to select their prefered timezone

Hello experts,

I have an PHP 5.2.6 application that all time related data are stored as UTC time in the database. But at the same time I'd like to give user the option to choose their prefered time zone when displaying time in UI.

But the problem is, I found out that there are literally hundreds of legal PHP timezones provided by the following website:

http://ca3.php.net/manual/en/timezones.php

It's gonna be really awkward to let user choose their prefered timezone from hundreds of options.

How to simply the number of selections? Basically I'm just looking for the number of Options similar to MS Windows timezone selection, from GMT- 0 to GMT - +12 or -12.

Also daylight saving needs to be taken into consideration as well.

Any suggestion will be really appreciated!
cjabitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Well, the short answer is you can either do it right or do a subset of it right, which is to say, you will be doing a lot of it wrong.  If your clients are not in the emerging nations of China or India, you may be able to get away with doing some of it wrong.

You might take a single timezone for each of the hours away from GMT and use that (total of 24 hours) as your collection of "allowable" time zones.  But there is a reason why there are so many different time zones, and that goes to the legal issues about time.  If a proposal is due at 5:00pm, and you don't know whether it is daylight savings time, you may be late and get disqualified!  The many timezones are not so much as to keep the time correctly with respect to the rotation of the earth; they are there to comply with local law and custom.  China has one time zone.  India has some where the difference is not an hour, but 15 minutes.  Imagine scheduling air travel through those places without knowing the local time! Go figure.

You're right that it's not easy to let user choose their preferred timezone from hundreds of options.  But they also speak a lot of different languages, and use different currencies.  

You might want to check the note about PECL's time zone data base here:
 http://ca3.php.net/manual/en/timezones.php

Best of luck, ~Ray
<?php
$my_time_zone = 'America/New_York'; // GMT-0500
date_default_timezone_set($my_time_zone);
 echo date('D,F j, Y, h:i:s A');
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cjabitAuthor Commented:
Hi Ray_Paseur, thanks for the info!I don't see any note on that page, is that the correct link (it's the same link as I provided)
0
Ray PaseurCommented:
Hi, cjabit:  Here is the line I was referring to...

Note: The latest version of the timezone database can be installed via PECL's » timezonedb. For Windows users, a pre-compiled DLL can be downloaded from the PECL4Win site: » php_timezonedb.dll.

It's in a box down the page (not one of the user contributed notes).

Best, ~Ray
0
Ray PaseurCommented:
Just a note - last night all of the continental USA went off Daylight Savings Time except for Arizona -- they don't ever go onto Daylight Savings Time in Arizona.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.