Possible Duplicate:
How can I determine a web user's time zone?
Which is the best way to do this ? php or javascript.Can someone provide me with some snippets ? thanks.
This question is related to
php
javascript
timezone
Just as Oded has answered. You need to have this sort of detection functionality in javascript.
I've struggled with this myself and realized that the offset is not enough. It does not give you any information about daylight saving for example. I ended up writing some code to map to zoneinfo database keys.
By checking several dates around a year you can more accurately determine a timezone.
Try the script here: http://jsfiddle.net/pellepim/CsNcf/
Simply change your system timezone and click run to test it. If you are running chrome you need to do each test in a new tab though (and safar needs to be restarted to pick up timezone changes).
If you want more details of the code check out: https://bitbucket.org/pellepim/jstimezonedetect/
On server-side it will be not as accurate as with JavaScript. Meanwhile, sometimes it is required to solve such task. Just to share the possible solution in this case I write this answer.
If you need to determine user's time zone it could be done via Geo-IP services. Some of them providing timezone. For example, this one (http://smart-ip.net/geoip-api) could help:
<?php
$ip = $_SERVER['REMOTE_ADDR']; // means we got user's IP address
$json = file_get_contents( 'http://smart-ip.net/geoip-json/' . $ip); // this one service we gonna use to obtain timezone by IP
// maybe it's good to add some checks (if/else you've got an answer and if json could be decoded, etc.)
$ipData = json_decode( $json, true);
if ($ipData['timezone']) {
$tz = new DateTimeZone( $ipData['timezone']);
$now = new DateTime( 'now', $tz); // DateTime object corellated to user's timezone
} else {
// we can't determine a timezone - do something else...
}
Source: Stackoverflow.com