Browse - Programming Tips - How can I get the current year in perl?

Date: 2016feb28
Language: perl
Keywords: getYear, now, today

Q.  How can I get the current year in perl?

A.

sub getCurrentYear() { return (localtime)[5] + 1900; }
Or slightly less compactly:
sub getCurrentYear() { my(@tm) = localtime(time()); return $tm[5] + 1900; }
Example use:
my $year = getCurrentYear(); print "year=$year\n";