Over a million developers have joined DZone.

DateTime: Generic Date And Time Script In Perl

·

### begin_: file metadata
    ### 
    ### 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"
    ### 

### 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";



Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}