[Fsfe-ie] X days left counter

Barry O'Donovan mail at barryodonovan.com
Tue May 17 01:06:10 CEST 2005


On Mon 16 May 2005 23:22, Ciaran O'Riordan wrote:
> Can someone tell me the javascript/whatever code needed for a webpage
> to display "There are X days until the second reading", where "X" is
> the number?
>
> Just that text string, nothing fancy.

<script type="text/javascript">
  millisecs_left = (new Date("June 1 2005")) - (new Date());
  document.write( "There are "
         + Math.floor( millisecs_left/1000/60/60/24 )
         + " days until the second reading."
  );
</script>

It's been a long time since I used JavaScript so I am not sure how 
browsers will handle the above "condensed code". The following might be 
safer:

<script type="text/javascript">
   now = new Date();
   deadline = new Date("July 1 2005");
   millisecs_left = deadline - now;
   days_left = Math.floor( ( ( (millisecs_left/1000) /60) / 60) / 24 );
   document.write( "There are " + days_left + " days until the second 
reading." );
</script>

I've tested and it works but YMMV.

Regards,
Barry O'Donovan
http://www.barryodonovan.com/




More information about the FSFE-IE mailing list