Solved

Allow user to select their prefered timezone

Posted on 2008-10-31
4
978 Views
Last Modified: 2011-09-20
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!
0
Comment
Question by:cjabit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 22854802
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
 

Author Comment

by:cjabit
ID: 22854926
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 22854936
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 22861927
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question