I’m building an app that’s going to be used by people in different countries, therefore different time zones. What I need to do is this, users can login to a room and start a poll. All users cast their votes and when they’re down the poll is over. First of all I need to store the start time and end time of polls in the db table. What datatype should I use?
Secondly, the users need to be able to view the poll results. If I display the poll results including start time and end time, those time stamps will be the server time obviously. But if someone in the UK or Israel is looking at that page, I need the time to be displayed in local browser time, make sense?
My understanding is that you need to store you dates in UTC time and then when you display the date you use the users time-zone offset. You could ether allow the user to set their own time-zones and store it part of their user account information or try to detect their time-zone, maybe using something like GeoIP. The PHP datetime class could be useful http://www.php.net/manual/en/class.datetime.php
I had a quick look at that class and didn’t see anything blatantly obvious, I’ll have a better look now. I don’t want to have the users do that themselves, there’s an existing app they’re using that does the timezone offset, just can’t get at the source code for that. Thanks for your input.