Solved

Allow user to select their prefered timezone

Posted on 2008-10-31
4
977 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
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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