On Tue, Mar 27, 2001 at 11:07:30PM +0100, Natalie Ford wrote:

> I need to put a countdown to a specific date on a web page.  Can anyone 
> tell me the best way to do this?  Is there something I have missed in HTML 
> itself that will do this?  Do I need JavaScript or Perl or ANOther?  Any 
> help will be much appreciated as I need to do this in a relatively short 
> time-frame (the next three days?!!)...

If you want the countdown to continually update after the page has loaded,
then you need Java[script].  If, however, you simply want to put a static
value into the page, then a bit o' perl like this should suffice (untested):

$futuretime=1e9;      # the epoch time of your future event
$timediff=$futuretime-time;

exit if($timediff<1); # don't want to have embarrassing negative numbers ...

$days=int($timediff/86400); $timediff%=86400 # 86400 seconds in a day
$hours=int($timediff/3600); $timediff%=3600  # 3600 seconds in an hour
$mins=int($timediff/60); $timediff%=60       # 60 seconds in a minute
$secs=$timediff;

print "$days Days, $hours Hours, $mins Minutes and $secs Seconds remain.";

Prettifying, and getting the correct singulars/plurals in there is left as
an exercise for the reader.  Months are a little tricky so I haven't
bothered :-)

-- 
David Cantrell | [EMAIL PROTECTED] | http://www.cantrell.org.uk/david/

    This is a signature.  There are many like it but this one is mine.

** I read encrypted mail first, so encrypt if your message is important **

PGP signature

Reply via email to