Solved

Allow user to select their prefered timezone

Posted on 2008-10-31
4
973 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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will learn how to count occurrences of each item in an array.
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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now