ilyash
11-15-2007, 02:31 AM
I need to convert my server time to user time.
How would I convert that assuming I know what country they are in.
Is there a list of countries -> timezone I could use?
thanks!
or if not by country.. how else?
mwaseem
11-15-2007, 02:47 AM
If you're registered with Google Analytics, log into analytics and click "Edit Analytics Account" and you'll see a list of countries with their time zones. i.e. for Pakistan, you'll get "(GMT+05:00) Karachi"
attached is the HTML source of that page :)
I hope it helps!
azizny
11-15-2007, 08:00 AM
I got the database somewhere. I'll see if I can get it for you.
Although the database is for cities, but I'll sure you can rebuild it for countries.
Peace,
sasha
11-15-2007, 08:47 AM
I need to convert my server time to user time.
How would I convert that assuming I know what country they are in.
Is there a list of countries -> timezone I could use?
thanks!
or if not by country.. how else?
From time to time countries and regions will change the way they deal with daylight savings time so so you might run in some problems with hardcoded list.
I like using javascript getTimezoneOffset() to guess user time zone and then (as all my data is always in mysql) I do something like this:
SELECT some_stuff, ... , DATE_FORMAT(CONVERT_TZ(`some_date_fild_name`,'SYSTEM','{$request_timezone}'),'%e/%c/%Y %H:%i') AS some_date FROM ...
$request_timezone is user time zone that looks like "-4:00"
"some_date" will be server time adjusted to display as user time.
In order for this to work mysql server needs to be setup to handle timezones. You can find more info here: http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html , but short summary is that initially and every time your tz_data package update you need to run:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
mojtabaf
11-15-2007, 09:48 AM
Why don't you just simply ask them? It's really easier. :D
If you like the hard work:
http://en.wikipedia.org/wiki/List_of_time_zones
http://www.datamystic.com/timezone/time_zones.html
the best one for your needs:
http://time_zone.tripod.com/
azizny
11-15-2007, 05:30 PM
Forgot to mention, the list I had also specifies the regular/saving time zones.
Peace,
ilyash
11-16-2007, 07:15 PM
I decided to just ask users their time zone.
Thanks anyway!
Another method would probably be using AJAX calls to a server side script passing the users time as a variable.
Compare this to the system time to find their timezone.