
Date and time with Perl
Author: John M. Gabriele | back to index
---
A small example:
#!/usr/bin/env perl use strict; use warnings; my $t = time; # Seconds since epoch. my ( $t2 ) = time; # Same. # Pass localtime() an arg of seconds since epoch. # Default is right now. my ( $year, $month, $day ) = ( localtime )[5,4,3]; $year += 1900; $month++; # Recall, count starts at 0. my $secs_per_day = 24 * 60 * 60; # In scalar context, yields a ctime-like string. my $couple_days_ago = localtime( time() - 2 * $secs_per_day );
See also the DateTime module on CPAN.