Forum Moderators: coopster

Message Too Old, No Replies

ISO timezone

Time zone php mysql

         

impact

2:54 pm on May 11, 2011 (gmt 0)

10+ Year Member



Hello,

I want to add a timezone selection option in my site. That is for every message i save into mysql, i can add a timezone.

A small check on the net and I found this but I dont understand, if I save these values into mysql, such as -12.0 or 12.0. How do I calculate the present time as per the time zone's time.

 <select name="DropDownTimezone" id="DropDownTimezone">
<option value="-12.0">(GMT -12:00) Eniwetok, Kwajalein</option>
<option value="-11.0">(GMT -11:00) Midway Island, Samoa</option>
<option value="-10.0">(GMT -10:00) Hawaii</option>
<option value="-9.0">(GMT -9:00) Alaska</option>
<option value="-8.0">(GMT -8:00) Pacific Time (US &amp; Canada)</option>
<option value="-7.0">(GMT -7:00) Mountain Time (US &amp; Canada)</option>
<option value="-6.0">(GMT -6:00) Central Time (US &amp; Canada), Mexico City</option>
<option value="-5.0">(GMT -5:00) Eastern Time (US &amp; Canada), Bogota, Lima</option>
<option value="-4.0">(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz</option>
<option value="-3.5">(GMT -3:30) Newfoundland</option>
<option value="-3.0">(GMT -3:00) Brazil, Buenos Aires, Georgetown</option>
<option value="-2.0">(GMT -2:00) Mid-Atlantic</option>
<option value="-1.0">(GMT -1:00 hour) Azores, Cape Verde Islands</option>
<option value="0.0">(GMT) Western Europe Time, London, Lisbon, Casablanca</option>
<option value="1.0">(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris</option>
<option value="2.0">(GMT +2:00) Kaliningrad, South Africa</option>
<option value="3.0">(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg</option>
<option value="3.5">(GMT +3:30) Tehran</option>
<option value="4.0">(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi</option>
<option value="4.5">(GMT +4:30) Kabul</option>
<option value="5.0">(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
<option value="5.5">(GMT +5:30) Bombay, Calcutta, Madras, New Delhi</option>
<option value="5.75">(GMT +5:45) Kathmandu</option>
<option value="6.0">(GMT +6:00) Almaty, Dhaka, Colombo</option>
<option value="7.0">(GMT +7:00) Bangkok, Hanoi, Jakarta</option>
<option value="8.0">(GMT +8:00) Beijing, Perth, Singapore, Hong Kong</option>
<option value="9.0">(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk</option>
<option value="9.5">(GMT +9:30) Adelaide, Darwin</option>
<option value="10.0">(GMT +10:00) Eastern Australia, Guam, Vladivostok</option>
<option value="11.0">(GMT +11:00) Magadan, Solomon Islands, New Caledonia</option>
<option value="12.0">(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka</option>
</select>


Thank you,

g1smd

6:52 pm on May 11, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I believe your list is incomplete. Some places can be +13 or -13 hours.

Don't use the term "GMT" at all. It was replaced by "UTC" in 1972.

You should not save the input timezone to the database. You should convert all inputted times to the UTC timezone and save the UTC value to the database.

You then use fetch the UTC data from the database and apply the viewers timezone offset to it in order to display it.

Input by person in India (UTC+0530) at 15:30 local time:

2011-05-11 15:30 (+0530) is stored as 2011-05-10 10:00 (UTC).

Person in New York (UTC-0500) views the data:

2011-05-11 10:00 (UTC) is shown as 2011-05-11 05:00 local time.

impact

1:38 am on May 12, 2011 (gmt 0)

10+ Year Member



Thank you for replying. Initially, I was thinking of making the option as

<option value="Asia/Kabul">(GMT +4:30) Kabul</option>

Then save "Asia/Kabul" in database and while retrieving I would set the default time zone into Asia/Kabul and then get the local time using PHP.

But in your case, I dont understand how to convert "5.5" into 2011-05-10 10:00 (UTC)? and what would be the MYSQL field type to store these kind of values and how to convert it into local time?

Please post a tutorial so that I can learn this.