README
NAME
DateTime::strftime - provide strftime() formatting for DateTime objects
SYNOPSIS
use DateTime::strftime;
say strftime(DateTime.now, '%c'); # default": EN
# Sun Jan 19 13:19:02 +0100 2025
say strftime(DateTime.now, '%c', "NL");
# zon 19 jan 13:19:02 +0100 2025DESCRIPTION
The DateTime::strftime distribution provides a strftime subroutine that takes a DateTime object, a strftime format string (or its :text: equivalent), and an optional locale indicator (which defaults to the dynamic variable $*LOCALE-DATES or "EN").
It returns the representation of the DateTime object according to that format and locale.
FORMAT SPECIFICATION
The supported formats are a (large) subset of strftime. The E and O modifiers are not supported.
Since the strftime format codes are rather cryptic (although very widely in use), one can also use an alternate :text: format. So instead of the rather cryptic "%c", one can also use ":datetime:".
Please note that one probably shouldn't use the %g and %y formats for anything that is persistent. Data and programs stay around longer then anybody expects, and we don't want another Y2K problem, especially in a 100-year programming language!
DEFAULT LOCALIZATION
my $*LOCALE-DATES = "NL";
say strftime($dt, ':weekdayname:'); # zondag
say strftime($dt, ':weekdayname:', "EN"); # SundayThe $*LOCALE-DATES dynamic variable can be set with the string of the desired localization, or with an instantiated Locale::Dates object. It will then affect any call to strftime that does not have an explicit localization specified.
LEXICAL REFINEMENT
use DateTime::strftime :refine;
say DateTime.now.strftime('%c'); # default": EN
# Sun Jan 19 13:19:02 +0100 2025
say DateTime.now.strftime(':datetime:', "NL");
# zon 19 jan 13:19:02 +0100 2025You can also use DateTime::strftime with the :refine parameter. This will add a strftime method to the DateTime class in the lexical scope in which the use statement is located. This allows one to not to have to change existing code using the DateTime class, while still having the added functionality of a DateTime.strftime method.
OTHER SOFTWARE
See also Jean Forget's Date::Calendar::Strftime and Date::Calendar::Gregorian.
AUTHOR
Elizabeth Mattijsen [email protected]
Source can be located at: https://codeberg.org/lizmat/DateTime-strftime . Comments and Pull Requests are welcome.
If you like this module, or what I'm doing more generally, committing to a small sponsorship would mean a great deal to me!
COPYRIGHT AND LICENSE
Copyright 2025, 2026 Elizabeth Mattijsen
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.