·  PERL – Date

 

- Info:

  - This tutorial shows how to work with date in Perl.

  - Additional info can be found at http://nb.inode.co.nz/articles/date_and_time_in_perl/.

 

- Procedure:

  - Create "PERL Console Application" Test.pl.

 

    Test.pl

    use Time::Local;  #Used only for timelocal function

    

    #Returns current date as number of non-leap seconds since 01.01.1970 UTC

    $currentTime = time();   

    print($currentTime."\n");

    

    #Returns date as string Tue Oct  2 14:07:29 2007.

    $humanTime = localtime($currentTime);

    print($humanTime."\n");

    

    #Returns date as array.

    my ($sec,$min,$hour,$mday,$mon,$year) = localtime($currentTime);

    $year = $year + 1900;

    $mon  = $mon  + 1;

    print($mday.".".$mon.".".+$year." ".$hour.":".$min.":".$sec."\n");

    

    #Returns date as number of non-leap seconds since 01.01.1970 UTC

    $mon  = $mon  - 1;

    $year = $year - 1900;

    my $thisyear = timelocal($sec,$min,$hour,$mday,$mon,$year);

    print($thisyear."\n");

    print(localtime($thisyear)."\n");

    

    output

    1191328360

    Tue Oct  2 14:32:40 2007

    2.10.2007 14:32:40

    1191328360

    Tue Oct  2 14:32:40 2007