Troy297
08-27-2007, 05:34 PM
Okay...
So I've made myself a working clock that gets the time accuratly in PHP but I need help on making it so that I can integrate it into my dynamic javascript clock....
<?php
$oh = "-4"; //Offset for hours
$om = "-20"; //Offset for minutes
list($hour, $minute, $second) = explode(' ', gmdate('H i s'));
$newdate = gmdate('H:i:s A', gmmktime($hour + $oh, $minute + $om, $second));
?>
Now I just can't figure out how to get the same effect/result using Javascript... here's the clock:
<script language="JavaScript">
<?php
$mins = "-20";
$hrs = "-4";
?>
function jsClockTimeZone(){
// Copyright 1999 - 2001 by Ray Stott
// Script available at http://www.crays.com/jsc
var time = new Date()
var hour = time.getUTCHours()+<?php echo $hrs;?>
var minute = time.getUTCMinutes()+<?php echo $mins;?>
var second = time.getUTCSeconds()
var temp = "" + ((hour > 12) ? hour - 12 : hour)
if(hour==0) temp = "12"
temp += ((minute < 10) ? ":0" : ":") + minute
temp += ((second < 10) ? ":0" : ":") + second
temp += (hour >= 12) ? " PM" : " AM"
document.clockFormTimeZone.digits.value = temp
setTimeout("jsClockTimeZone()",1000)
}
//-->
</script>
You see the problem is that the Javascript doesn't do the adding in "24-hour mode" as I would want it to do... Is there anyway for the Javascript to get its vars for hours and minutes from the PHP and then have them re-evaluate themselves every 50 seconds or something?
Thanks again!
So I've made myself a working clock that gets the time accuratly in PHP but I need help on making it so that I can integrate it into my dynamic javascript clock....
<?php
$oh = "-4"; //Offset for hours
$om = "-20"; //Offset for minutes
list($hour, $minute, $second) = explode(' ', gmdate('H i s'));
$newdate = gmdate('H:i:s A', gmmktime($hour + $oh, $minute + $om, $second));
?>
Now I just can't figure out how to get the same effect/result using Javascript... here's the clock:
<script language="JavaScript">
<?php
$mins = "-20";
$hrs = "-4";
?>
function jsClockTimeZone(){
// Copyright 1999 - 2001 by Ray Stott
// Script available at http://www.crays.com/jsc
var time = new Date()
var hour = time.getUTCHours()+<?php echo $hrs;?>
var minute = time.getUTCMinutes()+<?php echo $mins;?>
var second = time.getUTCSeconds()
var temp = "" + ((hour > 12) ? hour - 12 : hour)
if(hour==0) temp = "12"
temp += ((minute < 10) ? ":0" : ":") + minute
temp += ((second < 10) ? ":0" : ":") + second
temp += (hour >= 12) ? " PM" : " AM"
document.clockFormTimeZone.digits.value = temp
setTimeout("jsClockTimeZone()",1000)
}
//-->
</script>
You see the problem is that the Javascript doesn't do the adding in "24-hour mode" as I would want it to do... Is there anyway for the Javascript to get its vars for hours and minutes from the PHP and then have them re-evaluate themselves every 50 seconds or something?
Thanks again!