PHP - Timezones
Hello,
I am a bit confused on how I want to go about developing my application. I see PHP is now moving towards dates using a Country/City format of dates. My question is how is everyone going about making simple timezone selectors (Like selecting the date/time on Windows) on their web applications? I really don't want to display a list of every city from America as there are a ton just in that category. Then I thought, we can calculate the time using an offset... Well php doesn't really have a function to set the time via an integral offset. So my question is... What is the best way to take a stab at this? The only way I can think of this is to make a list of the timezones, have an offset such as +1, +2, +3.... and then have an array that links the offset to the Country/City date format and then use that to set the default timezone lol Thanks in advance! Owner Similar Tutorialsim setting up timezones so every user will be able to have the times displayed in their timezone. however when they register their timezone is sent to the database as an integer value: eg/ -3. meaning -3 hours from GMT. but to set the timezone in php i am using: date_default_timezone_set(); i have the list of available timezones but they just display the names and not the hour difference. Is there any where to get such a list or should i be doing things differently? hey guys trying to think of a practical way for a user to select his/her timezone without having to listing all in a select element like so:
Europe/London, Europe/Luxembourg, Asia/Singapore etc...
i was thinking of having a select element listing +00:00, +01:00 etc... but i would have the problem of DST when clocks change
what is the best solution for this please?
thank you
So the most relevant thread I found was here, I just want to get a little more information. In an application I'm developing, a user may decide to change their timezone. Currently I'm setting my timezone to GMT with date_default_timezone_set(). However I just realized that when inserting date into MySQL DATETIME fields it is (quite obviously) using the server time. So what is the best method here. Use SET GLOBAL time_zone = timezone; as indicated in the MySQL manual. Change my field types to TIMESTAMP instead, from what I've read it converts it to UTC (which in essence is GMT) before storing in the database. After testing this though, it still inserts NOW() as the servers date/time. So not sure what the go is there. Store a UNIX timestamp in the database, and convert it before display with PHP. I'm at a loss here as to what would be the cleanest, and most suitable solution for an application that depends heavily on the timezone so it can accurately display dates and time. Cheers. hey guys I wanting some information on the best way to store a timestamp and how I would convert that timestamp to another timezone please?
im guessing I would firstly store all timestamps to the database in GMT OR BST then convert after according to users timezone preference?
Is there a good website for this please on how this is possible...thank you
As you may of guessed, it's a nightmare. If my birthday is on 10th June GMT, it would still be my birthday on the 11th June in Australian time. Though.. the 11th June, is not my birthday. It's not hard to understand this bit as Australia is like.. many hours ahead. Though when it comes to PHP... if I used some Timezone plug-in then this would bring up the same result as it does now. Though when that persons age is displayed... if my birthday is 10th June at 1AM, in America, it would be the 9th June. There for, they won't see my age change to 18 until it is 10th June their time. To prevent this, is when calculating the persons age, you would be adding their timezone offset onto their birthday timestamp. So regardless on what day it is around the world, if they are celebrating their birthday... then it's their birthday all around the world even though it's different times. To do this, i would need timezone offsets. I would have a field in the database I assume. I would convert their DOB to timestamp. I would add their offset onto that timestamp or take it away and display whatever result that gives to every user. This would display their age as whatever to every user. The next problem is... strtotime works in MM/DD/YYYY, so how do I make it work with DD/MM/YYYY ? I'm actually not making much sense, how would you work with Timestamps and Ages? Also for my next question question, if I had someones DOB, how do I bring up their next birthday out of it for when I am displaying "Bobs birthday is on the..." Now for final, apparently on 19th Jan 2038 the UNIX Timestamp will cease to work due to a 32-bit overflow. How can this be true when converting a date in the year 2500 still brings a timestamp? |