localtime#

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"

Description#

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:

Index

Field

Range

0

$sec

0-60 (60 = leap)

1

$min

0-59

2

$hour

0-23

3

$mday

1-31

4

$mon

0-11 (Jan = 0)

5

$year

years since 1900

6

$wday

0-6 (Sun = 0)

7

$yday

0-365

8

$isdst

DST 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.

See also#

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