Xexi
Oct 19th 2008, 9:13 pm
So I have this code that someone else wrote and I have cron jobs setup to execute every 10 minutes.
What I would lke to display is another timer counting down from the 10 minute mark below it.
Example:
10:14:22PM <~ Current script
05:38 seconds until next event <~ I would like to add this
//clock() recieves server time in php:
//javascript:clock(".date('G,i,s').") (24-hour format, Minutes, Seconds)
var hours;
var minutes;
var seconds;
var timer=null;
var timed=null;
function clock(hour,minute,second){
hours=hour;
minutes=minute;
seconds=second;
if(timer){clearInterval(timer);timer=null;}
timer=setInterval("work();",1000);
}
function addZero(_v)
{
if(_v<10)_v="0"+_v;
return _v;
}
function work(){
if (!document.layers && !document.all && !document.getElementById) return;
var runTime = new Date();
var nd = "AM";
var shours = hours;
var sminutes = minutes;
var sseconds = seconds;
if (shours >= 12) {
nd = "PM";
shours-=12;
}
if (!shours) shours = 12;
sminutes=addZero(sminutes);
sseconds=addZero(sseconds);
shours =addZero(shours );
movingtime = ""+ shours + ":" + sminutes +":"+sseconds+"" + nd;
if (document.getElementById) {
document.getElementById("jsClock").innerHTML=movingtime;
}
else if (document.layers)
{
document.layers.clock.document.open();
document.layers.clock.document.write(movingtime);
document.layers.clock.document.close();
}
else if (document.all) {
clock.innerHTML = movingtime;
}
if(++seconds>59) {
seconds=0;
if(++minutes>59)
{
minutes=0;
if(++hours>23)
{
hours=0;
}
}
}
}
Any help would be appreciated :)
What I would lke to display is another timer counting down from the 10 minute mark below it.
Example:
10:14:22PM <~ Current script
05:38 seconds until next event <~ I would like to add this
//clock() recieves server time in php:
//javascript:clock(".date('G,i,s').") (24-hour format, Minutes, Seconds)
var hours;
var minutes;
var seconds;
var timer=null;
var timed=null;
function clock(hour,minute,second){
hours=hour;
minutes=minute;
seconds=second;
if(timer){clearInterval(timer);timer=null;}
timer=setInterval("work();",1000);
}
function addZero(_v)
{
if(_v<10)_v="0"+_v;
return _v;
}
function work(){
if (!document.layers && !document.all && !document.getElementById) return;
var runTime = new Date();
var nd = "AM";
var shours = hours;
var sminutes = minutes;
var sseconds = seconds;
if (shours >= 12) {
nd = "PM";
shours-=12;
}
if (!shours) shours = 12;
sminutes=addZero(sminutes);
sseconds=addZero(sseconds);
shours =addZero(shours );
movingtime = ""+ shours + ":" + sminutes +":"+sseconds+"" + nd;
if (document.getElementById) {
document.getElementById("jsClock").innerHTML=movingtime;
}
else if (document.layers)
{
document.layers.clock.document.open();
document.layers.clock.document.write(movingtime);
document.layers.clock.document.close();
}
else if (document.all) {
clock.innerHTML = movingtime;
}
if(++seconds>59) {
seconds=0;
if(++minutes>59)
{
minutes=0;
if(++hours>23)
{
hours=0;
}
}
}
}
Any help would be appreciated :)