Welcome visitor
* Login
* Register
It is currently March 18th, 2019, 3:25 pm
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » JavaScript



Post new topic Reply to topic  [ 2 posts ] 
Author Message
  Countdown Calendar with JavaScript
PostPosted: December 18th, 2009, 9:29 am 

Posts: 17
Hey, I would like to show a countdown calendar on my site. I don't have access to a server side code, so I'd been considering a JavaScript solution. Do you think you can help me?

What I have is a date, and I would like to show the remaining time for that date, for example
Jan 1st 2010 is around the corner!
11 days 8h 45m 12s left


Top
 Profile  
 
  Re: Countdown Calendar with JavaScript
PostPosted: December 18th, 2009, 6:15 pm 
User avatar

Posts: 44
This is an example for the 2012 end of the world:

<body onload="frundate();rundate();">

December 21st 2012 is near!
<br /><br />
<span id="d"></span> days : <span id="h"></span> hours :
<span id="m"></span> mins : <span id="s"></span> secs left

<script type="text/javascript">

/*this is to set the "limit" date*/
var t = new Date();
ly=2012;
lm=11;
ld=21;
lh=0;
lmn=0;
ls=0;
t.setFullYear(ly,lm,ld);
t.setUTCHours(lh,lmn,ls);
totals=Math.ceil(t.getTime()/1000);

/*this is to get the current date*/
var today = new Date();
todays=Math.ceil(today.getTime()/1000);

/*now we find the seconds between the 2 dates*/
secondsl=totals-todays;

/*arithmetic to find days, hours, etc.*/
fd=Math.floor(secondsl/86400);
sr=secondsl-fd*86400;
fh=Math.floor(sr/3600);
sr=sr-fh*3600;
fm=Math.floor(sr/60);
fs=sr-fm*60;
fr=fd+':'+fh+':'+fm+':'+fs;

/*this functions fills the contdown spaces*/
function frundate()
{
document.getElementById('d').innerHTML=fd;
document.getElementById('h').innerHTML=fh;
document.getElementById('m').innerHTML=fm;
document.getElementById('s').innerHTML=fs;
}

/*this is the "clock"*/
function rundate()
{
time=setTimeout("rundate()",1000);
fs=fs-1;
if(fs<0)
  {
  fs=59;
  fm=fm-1;
  }
document.getElementById('s').innerHTML=fs;
if(fm<0)
  {
  fm=59;
  fh=fh-1;
  }
document.getElementById('m').innerHTML=fm;
if(fh<0)
  {
  fh=23;
  fd=fd-1;
  }
document.getElementById('h').innerHTML=fh;
if(fd<0)
  {
  fd=0;
  document.getElementById('d').innerHTML=fd;
  alert('2012 is here!');
  return false;
  }
}
</script>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

FORUMS » Client Side » JavaScript


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron