Timezone Display Script - PHP/JS<

liunx

Guest
This is the timezone script I have at the moment. It is javascript obviously, and isn't yet dynamic. I have echoed it to place it in my PHP page, but there is one thing missing. As it is, the starting time is set to 09:27:03 and I would obviously like the script to sync with the server time. Is it possible to re-enter PHP in the middle of an "echo"? If so, can I simply just add the PHP date variables inside the echo?

Here's the code:

echo '<span style="font-size:9pt;color:#000066;font-family:arial;">Ottawa:</span>'
.'<input name="OTTAH" type="text" size="2" readonly style="font-family:courier;font-size:9pt; border-style:none; background-color:#ffffff; color:#000099; text-align:right;" value=9>.<input name="OTTAM" type="text" size="2" readonly style="font-family:courier;font-size:9pt; border-style:none; background-color:#ffffff; color:#000099;text-align:right;" value=27>.<input name="OTTAS" type="text" size="2" readonly style="font-family:courier;font-size:9pt; border-style:none; background-color:#ffffff; color:#000099;text-align:right;" value=3><br>';
echo '<script type= "text/javascript" language="JavaScript">
<!--
function jsOTTATimeZone(){
var hours;
var minutes;
var seconds;
var thours;
var tminutes;
var tseconds;

seconds=OTTAS.value;
if (seconds.substring(0,1)=="0")
{
seconds=seconds.substring(1,2);
}
if (seconds=="")
{
seconds="0";
}
seconds=parseInt(seconds);

hours=OTTAH.value;
if (hours.substring(0,1)=="0")
{
hours=hours.substring(1,2);
}
if (hours=="")
{
hours="0";
}
hours=parseInt(hours);

minutes=OTTAM.value;
if (minutes.substring(0,1)=="0")
{
minutes=minutes.substring(1,2);
}
if (minutes=="")
{
minutes="0";
}
minutes=parseInt(minutes);

seconds=seconds +1;

if (seconds>59)
{
seconds=0;
minutes=minutes+1;
}

if (minutes>59)
{
minutes=0;
hours=hours+1;
}

if(hours>24)
{
hours=0;
}

if (seconds<=9)
{
OTTAS.value="0" + seconds;
}
else
{
OTTAS.value=seconds;
}

if (minutes<10)
{
minutes= "0" + minutes;
}

if (hours<10)
{
hours= "0" + hours;
}

OTTAH.value=hours;
OTTAM.value=minutes;


setTimeout("jsOTTATimeZone()",1000);
}
jsOTTATimeZone();
//-->
</script>';


Any help would be greatly appreciated.

PS, Apologies for the formatting problem.Figured out my solution. Please disregard.Originally posted by Spire2000
Figured out my solution. Please disregard. And what was it?when echoing...single quotes aren't processed as php..in order to embed a function call or such into it,use dots to conatecate(sp x.x) the string parts of the expression to each side of the function call:


echo 'string'.function().'string';
echo 'string'.function();
echo function().'string';Yeah, I set my variables:


$hour = date("H");
$hourMaritime = date("H")+1;
$hourGMT = date("H")+4;
$minute = date("i");
$second = date("s");


and then placed them like this:


echo '<span style="font-size:9pt;color:#000066;font-family:arial;">Ottawa:</span>'
.'<input name="OTTAH" type="text" size="2" readonly style="font-family:courier;font-size:9pt; border-style:none; background-color:#ffffff; color:#000099; text-align:right;" value='.$hour.'>.<input name="OTTAM" type="text" size="2" readonly style="font-family:courier;font-size:9pt; border-style:none; background-color:#ffffff; color:#000099;text-align:right;" value='.$minute.'>.<input name="OTTAS" type="text" size="2" readonly style="font-family:courier;font-size:9pt; border-style:none; background-color:#ffffff; color:#000099;text-align:right;" value='.$second.'><br>';


For each time zone I had to create a slightly different block of code, offsetting the time in the hour variable. The only problem I'm strugglig with now is how to set the variables correctly for a time zone that is offset by a half hour and not a full hour...
 
Back
Top