?
Solved

Allow user to select their prefered timezone

Posted on 2008-10-31
4
Medium Priority
?
981 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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 111

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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

718 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