Jump to content

Perl Programming/Keywords/localtime

From Wikibooks, open books for an open world
Previous: local Keywords Next: lock

The localtime keyword

[edit | edit source]

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 | edit source]
  localtime EXPRESSION
  localtime

Examples

[edit | edit source]
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 | edit source]
gmtime localtime time times utime
Previous: local Keywords Next: lock