Forum Moderators: coopster
Could you view this test page and check if the current time is correct?
Thank you.
I'm looking forward to the feedback.
Anand
[edited by: coopster at 8:21 pm (utc) on Feb. 23, 2006]
[edit reason] no urls please TOS [webmasterworld.com] [/edit]
If you wanted to show some code we would be happy to help you confirm and troubleshoot any issues.
Below is the code that displays the GMT and the current local time of the visitor. I calculate the current local time with the Javascript function getTimezoneOffset and PHP.
I'm not sure if the code is correct, but it works for my local time. I don't know if it works in other countries.
I use a form, because I want to use the value from getTimezoneOffset (javascript).
Does anybody have any suggestions?
<?php
if (isset($_POST['tzoffset']))
{
$offset = -$_POST['tzoffset'];
$time = time() + (3600 * $offset);
$gmt = gmdate("Y-m-d H:i:s", $time);
echo "Your current time is: <strong>".$gmt. "</strong><br>";
}
echo "<br>GMT is: " .gmdate("Y-m-d H:i:s"). "<br><br>";
?>
<form method="post" id="testform" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="hidden" name="tzoffset">
<input type="submit" value="Show my current time">
</form>
<script type="text/javascript">
window.onload = function() {timezoneoffset();}
function timezoneoffset()
{
var now = new Date();
var offset = now.getTimezoneOffset()/60;
document.getElementById('testform').tzoffset.value = offset;
}
</script>
Perhaps a pulldown menu with timezones is a good idea?
I can for instance use the timezones used in Windows (double click on the clock in the system tray and choose tab "Time Zone").