Yes I really know this isn't much of a CUFP, since it's been done many times before, but just change
$date2
and you have a handy countdown to any time you want!
#!/usr/bin/perl ###Load Modules use warnings; use strict; use Date::Manip; use Time::HiRes; use CGI; my $cgi = new CGI; ###Set $err so you can specify a mode for &DateCalc my $err; ###Set Dates to Calculate for, then Find Difference my $curtime = getime(); my $date1 = &ParseDate($curtime); my $date2 = &ParseDate("03:14:06 Jan 19 2038"); my $delta = &DateCalc($date1,$date2,\$err,1); ###Populate Data hash my %data; @data{qw/years months weeks days hours minutes seconds/} = $delta =~ / +(\d+)/g; ###Begin HTML Output, yes this is bad, but it's quick-n-dirty :) print $cgi->header(); print<<END; <html> <head> <title>Countdown to the Death of 32bit time_t</title> </head> <body> <h3> Countdown to the Death of 32bit time_t (Tue Jan 19 3:14:06 203 +8 GMT) </h3> <hr> <p> $data{years} Year(s) </p> <p> $data{months} Months(s) </p> <p> $data{weeks} Weeks(s) </p> <p> $data{days} Day(s) </p> <p> $data{hours} Hour(s) </p> <p> $data{minutes} Minutes(s) </p> <p> $data{seconds} Second(s) </p> <hr> <p> END my $now = &getime(); print<<END; It is curently $now </p> </bodY> </html> END ###Get current time (GMT) sub getime() { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime( +); ###Correct for 'zero math' $year += 1900; $mon += 1; my $time = "$hour:$min:$sec $mon\/$mday\/$year"; return $time; }

Yes I know it's not the best script around, or best written, but I like it

Edit: Changed

sub getime() {
to
sub getime {
and fixed the month 'count-from-zero' bug.

Replies are listed 'Best First'.
Re: Death of time_t Timer
by Nkuvu (Priest) on Jun 18, 2003 at 21:34 UTC
    Change

    sub getime() {

    to

    sub getime {

    to lose that particular error. Also note that the month returned is 0..11 -- so you might want to add one to it in getime.

    Edit: Forgot to mention: Be sure you know the difference between calling a sub via &getime() and getime(). You might want the latter form. See perlsub for more info.

      Also note that the month returned is 0..11 -- so you might want to add one to it in getime.

      Doh! :)

      Forgot to mention: Be sure you know the difference between calling a sub via &getime() and getime(). You might want the latter form. See perlsub for more info.

      That has to do with @_ right?

        That has to do with @_ right?

        Partially. See this relevant bit from the perldoc:

        NAME(LIST); # & is optional with parentheses. NAME LIST; # Parentheses optional if predeclared/imported. &NAME(LIST); # Circumvent prototypes. &NAME; # Makes current @_ visible to called subroutine.

        So the passing of @_ is affected, as is the prototyping. I'm not too familiar with prototypes in Perl, so I'm not sure how things are affected when prototypes are circumvented... which is why I pointed to the perldocs instead of spelling it out myself. I know there's a difference, but haven't really looked into it. ;)