strftime#

Format a broken-down time as a string using a format template.

Synopsis#

use POSIX qw(strftime);
my @tm = localtime;
my $str = strftime("%Y-%m-%d %H:%M:%S", @tm);

What you get back#

A byte string formatted according to the template. Argument order matches localtime / gmtime: second, minute, hour, mday, mon (0-11), year (years since 1900), wday, yday, isdst — the last three optional and defaulting to -1.

Edge cases#

  • Fewer than seven arguments (format plus the first six tm fields): returns the empty string.

  • Output truncated at 1024 bytes.

  • Month is 0-11 and year is years-since-1900, the struct tm convention, not the 1-12 / 4-digit-year human convention.

Differences from upstream#

Fully compatible with upstream POSIX.

See also#

  • mktime — go the other way: broken-down time → epoch seconds.

  • asctime, ctime — simpler canned-format alternatives.