[thelist] Perl Date/Time

CDitty mail at redhotsweeps.com
Wed Feb 7 02:51:31 CST 2001


Can anyone tell me how to get the current date/time in perl in this format 
(2001-02-07 00:45:41)?  I have been able
to find enough info to get everything in a format close to that (2001-2-7 
1:31:41), but I need everything
but the year in 2 digits.

Here is my code.   It's very rough.  If anyone can shorten this, be my 
guest.  :)

print "Content-type: text/html\n\n";
$mytime1 = (localtime)[5]; # year
$mytime1 = $mytime1 + 1900;
$mytime2 = (localtime)[4]; # month
$mytime2 = $mytime2 + 1;
$mytime3 = (localtime)[3]; # day
$mytime4 = (localtime)[2]; # hour
$mytime5 = (localtime)[1]; # minute
$mytime6 = (localtime)[0]; # second

print "$mytime1-$mytime2-$mytime3 $mytime4:$mytime5:$mytime6 \n";


Any help is appreciated.

Thanks

Chris





More information about the thelist mailing list