View Single Post
Old 05-16-2008, 04:55 AM   PM User | #3
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,714
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
Here is a script that does this (tested with various time zones, including some of the 1/2 hour and 3/4 hour ones) -

PHP Code:
<?php
if (isset($_GET['offset'])) {
    
$minutes $_GET['offset'];
    echo 
"GMT offset (in minutes, from the browser): "$minutes ."<br />\n";
    echo 
"GMT: "gmdate("Y-m-d H:i:s") ."<br />\n";
    
    
$local gmmktime(gmdate("H"),gmdate("i")-$minutes); // adjust GMT by client's offset
    
    
echo "Calculated client's date/time: "gmdate("Y-m-d h:i:s a",$local) ."<br />\n";
} else {
    echo 
"<script language='javascript'>\n";
    echo 
"var d = new Date();\n";
    echo 
"location.href=\"${_SERVER['SCRIPT_NAME']}?offset=\" + d.getTimezoneOffset();\n";
    echo 
"</script>\n";
    exit();
}
?>
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is online now   Reply With Quote