how in lamp (LINUX ,APACHE ,MYSQL ,PHP) environme开发者_如何学Gont , can i show date and time in web page according to the user time zone ?
THANKS
Use JavaScript to determine the timezone of the user:
new Date().gettimezoneOffset()
On the PHP side this code works fine...
echo <<<EOE
<script type="text/javascript">
if (navigator.cookieEnabled)
document.cookie = "tzo="+ (- new Date().getTimezoneOffset());
</script>
EOE;
if (!isset($_COOKIE['tzo'])) {
echo <<<EOE
<script type="text/javascript">
if (navigator.cookieEnabled) document.reload();
else alert("Cookies must be enabled!");
</script>
EOE;
die();
}
$ts = new DateTime('now', new DateTimeZone('GMT'));
$ts->add(DateInterval::createFromDateString($_COOKIE['tzo'].' minutes'));
精彩评论