Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

localtime

Converts a Unix timestamp to the local time zone, returning either a 9-element list or a human-readable string depending on context.

If called without an argument (or with undef), uses the current time. In list context, returns a 9-element list:

IndexFieldRange
0$sec0-60 (60 = leap)
1$min0-59
2$hour0-23
3$mday1-31
4$mon0-11 (Jan = 0)
5$yearyears since 1900
6$wday0-6 (Sun = 0)
7$yday0-365
8$isdstDST flag (-1, 0, 1)

In scalar context, returns a ctime-style string like "Thu Jan 1 00:00:00 1970".

Uses libc::localtime_r for accurate timezone/DST handling.

Synopsis

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
    = localtime($time);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
    = localtime();           # uses current time
my $str = localtime($time);  # "Thu Jan  1 00:00:00 1970"

See Also

gmtime, time, POSIX::strftime, POSIX::mktime