You are here iC Home > Perl > Date & Time in Perl

Perl

4 Date & Time in Perl

29.08.2008
3.3 IDN Punycode [  up  ] - [ a - z ] - [ search PC ] - [ top ] 4.1 Date & Time Calculations (Date::Manip)

4.1   Date & Time Calculations (Date::Manip)
4.2   Format Time
4.3   Calculate Easter Day
4.4   Calculate Weekday
4.5   Related Date & Time Links

Common usage

my $tstamp = time();
my ($y, $m, $d, $ss, $mm, $hh) = (localtime($tstamp))[5,4,3,0,1,2];
$y += 1900;
$m += 1;

A timestamp function

sub tstamp () {
        my ($y, $m, $d, $ss, $mm, $hh) = (localtime())[5,4,3,0,1,2];
        $y += 1900;
        $m += 1;
        sprintf("%d%02d%02d%02d%02d%02d", $y, $m, $d, $hh, $mm, $ss);
}

Convert epoch seconds into a human-readable date

$ cat epoch.pl
#!/usr/bin/perl -w
use strict;
use Date::Manip;

my $epoch = $ARGV[0] || time() - 3600 * 24; # yesterday

print "-> epoch = $epoch\n";

my $date = &ParseDateString("epoch $epoch");

print "<- $date\n";



See also:
/perl/date time


Advanced search tips
3.3 IDN Punycode [  up  ] - [ top ] 4.1 Date & Time Calculations (Date::Manip)



[ home ] - [ search ] - [ feedback ]

copyright by reto - created with mytexi