DateTime: generic date and time script in perl
1 2 ### begin_: file metadata 3 ### <region-file_info> 4 ### main: 5 ### - name : DateTime.pl 6 ### desc : DateTime: generic date and time script in perl 7 ### date : created="Thu 2005-12-01 10:04:52" 8 ### last : lastmod="Thu 2005-12-01 10:04:59" 9 ### </region-file_info> 10 11 ### begin_: initialize perl (optional) 12 use strict; 13 use warnings; 14 15 ### begin_: initialize DateTime values 16 my %dttime = (); 17 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); 18 19 ### begin_: initialize DateTime number formats 20 $dttime{year } = sprintf "%04d",($year + 1900); ## four digits to specify the year 21 $dttime{mon } = sprintf "%02d",($mon + 1); ## zeropad months 22 $dttime{mday } = sprintf "%02d",$mday; ## zeropad day of the month 23 $dttime{wday } = sprintf "%02d",$wday + 1; ## zeropad day of week; sunday = 1; 24 $dttime{yday } = sprintf "%02d",$yday; ## zeropad nth day of the year 25 $dttime{hour } = sprintf "%02d",$hour; ## zeropad hour 26 $dttime{min } = sprintf "%02d",$min; ## zeropad minutes 27 $dttime{sec } = sprintf "%02d",$sec; ## zeropad seconds 28 $dttime{isdst} = $isdst; 29 30 ### begin_: xnpDate print iso8601 version date 31 print "$dttime{year}-$dttime{mon}-$dttime{mday}\n"; 32 33 ### begin_: xnpNow show system time 34 print "$dttime{year}-$dttime{mon}-$dttime{mday} $dttime{hour}:$dttime{min}:$dttime{sec} \n";