Perl Programming/Keywords/localtime

Previous: local Keywords Next: lock

The localtime keyword

edit

localtime is a function that converts a time as returned by the time function to a nine-element list with the time analyzed for the local time zone. If used without EXPRESSION, the contents of $_ are used.

Syntax

edit
  localtime EXPRESSION
  localtime

Examples

edit
  The code
($s, $min, $h, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);

$year += 1900;

print $isdst . " " . $yday . ". day of the year, " . $wday . ". day of the week\n";
print $year . '-' . qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon] . '-' . $mday . ' ' . $h . ':' . $min . ':' . $s . "\n";
returns on Windows something like:
0 47. day of the year, 2. day of the week
2015-Feb-17 15:20:18

See also

edit
gmtime localtime time times utime
Previous: local Keywords Next: lock