### begin_: file metadata ### <region-file_info> ### main: ### - name : DateTime.pl ### desc : DateTime: generic date and time script in perl ### date : created="Thu 2005-12-01 10:04:52" ### last : lastmod="Thu 2005-12-01 10:04:59" ### </region-file_info> ### begin_: initialize perl (optional) use strict; use warnings; ### begin_: initialize DateTime values my %dttime = (); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); ### begin_: initialize DateTime number formats $dttime{year } = sprintf "%04d",($year + 1900); ## four digits to specify the year $dttime{mon } = sprintf "%02d",($mon + 1); ## zeropad months $dttime{mday } = sprintf "%02d",$mday; ## zeropad day of the month $dttime{wday } = sprintf "%02d",$wday + 1; ## zeropad day of week; sunday = 1; $dttime{yday } = sprintf "%02d",$yday; ## zeropad nth day of the year $dttime{hour } = sprintf "%02d",$hour; ## zeropad hour $dttime{min } = sprintf "%02d",$min; ## zeropad minutes $dttime{sec } = sprintf "%02d",$sec; ## zeropad seconds $dttime{isdst} = $isdst; ### begin_: xnpDate print iso8601 version date print "$dttime{year}-$dttime{mon}-$dttime{mday}\n"; ### begin_: xnpNow show system time print "$dttime{year}-$dttime{mon}-$dttime{mday} $dttime{hour}:$dttime{min}:$dttime{sec} \n";
You need to create an account or log in to post comments to this site.