in a script, the variables are defined with "my".
I now have the variable
my $timestamp = time();
inserted and would now like to output the year.
With
my $timestamp = time();
my $year=$timestamp;
the timestamp is displayed correctly in the print
section with $year
.
How do I have to define $year
so that the date, e.g. date(Y)
is output?
Use localtime instead.
my @t = localtime;
print $t[5] + 1900;
Or reach for something more highlevel:
use Time::Piece;
my $time = localtime;
print $time->year;
See Time::Piece for details.