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 tmconvention, not the 1-12 / 4-digit-year human convention.$wdayand$ydayare accepted and IGNORED, as upstream ignores them. Both are derived from the date, so passing a wrong weekday cannot produce a wrong%A; passing none is the normal call.Out-of-range fields normalise rather than being echoed back: month 12 is January of the following year.
Differences from upstream#
Fully compatible with upstream POSIX.
See also#
mktime- go the other way: broken-down time to epoch seconds.asctime,ctime- simpler canned-format alternatives.