back to notes

Perl Time Snippet

my @now = localtime; $now[5] += 1900; $now[4] += 1; for my $l (0 .. (scalar(@now) - 1)) { $now[$l] = sprintf("%02d",$now[$l]); }

--or--

my @names = ('sec','min','hour','mday','mon','year','wday','yday','isdst');
my @time = localtime(time);

$time[5] = ($time[5] + 1900) - 2000; $time[4] = $time[4] + 1;
my %_t; @_t{@names} = @time; my ($t) = \%_t;

-- or --

use POSIX qw(strftime);
strftime("%Y-%m-%d %H:%M:%S",localtime)


last updated october 2023