Name | strftime Equivalent |
CPAN:Time::Format Equivalent |
Value | Example | Comment |
---|---|---|---|---|---|
$seconds |
%S |
ss |
seconds | 59 | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME%, DateTimePlugin (aliases: $sec ), SpreadSheetPlugin ( $FORMATTIME() - aliases: $second , $sec ). Both zero-fill to 2 digits. |
s |
seconds | 1 | Seconds, no leading zero. | ||
?s |
seconds | 1 | Seconds, leading space if less than 10. | ||
$minutes |
%M |
mm |
minutes | 59 | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME%, DateTimePlugin (aliases: $min ), SpreadSheetPlugin ( $FORMATTIME() - aliases: $minute , $min ). Both zero-fill to 2 digits. |
m |
minutes | 1 | Minutes, no leading zero. Note that the Time::Format code is ambiguous; it is the same as the code for the month. | ||
?m |
minutes | 1 | Minutes, leading space if less than 10. Note that the Time::Format code is ambiguous; it is the same as the code for the month. | ||
$hours |
%H |
hh |
hours (24-hour clock) | 23 | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME%, DateTimePlugin (aliases: $hour ), SpreadSheetPlugin ( $FORMATTIME() - aliases: $hour ). Both zero-fill to 2 digits. |
h |
hours | 1 | Hours, no leading zero. | ||
?h |
hours | 1 | Hours, leading space if less than 10. | ||
%I |
HH |
hours (12-hour clock) | 11 | ||
H |
hours (12-hour clock) | 1 | Hours, no leading zero. | ||
?H |
hours (12-hour clock) | 1 | Hours, leading space if less than 10. | ||
am |
am/pm designation (for 12-hour clock) | am | Displays "pm" if noon or later. Aliases: pm |
||
a.m. |
am/pm designation, with periods (for 12-hour clock) | a.m. | Displays "p.m." if noon or later. Aliases: p.m. |
||
AM |
AM/PM designation (for 12-hour clock) | AM | Displays "PM" if noon or later. Aliases: PM |
||
A.M. |
AM/PM designation, with periods (for 12-hour clock) | A.M. | Displays "P.M." if noon or later. Aliases: P.M. |
||
$day |
%d |
dd |
day of month | 31 | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME%. Zero-filled to 2 digits. |
d |
day of month | 1 | Single digit days have no leading fill characters. | ||
%e |
?d |
day of month | 1 | Single digit days have a leading space (instead of zero). | |
$wday |
%a |
Day |
Day of the week abbreviation (Sun, Mon, Tue, Wed, Thu, Fri, Sat) | Thu | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME%, SpreadSheetPlugin |
DAY |
Day of the week abbreviation, uppercase | THU | |||
day |
Day of the week abbreviation, lowercase | thu | |||
$weekday |
%A |
Weekday |
Day of the week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) | Thursday | Used by SpreadSheetPlugin |
$lwday |
%A |
Weekday |
Day of the week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) | Thursday | Used by DateTimePlugin |
WEEKDAY |
Day of the week, uppercase | THURSDAY | |||
weekday |
Day of the week, lowercase | thursday | |||
$month |
%b |
Abbreviated month name | Dec | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME%, DateTimePlugin. | |
$month |
%m |
2 digit month | 12 | Used by SpreadSheetPlugin. Zero filled. | |
$mo |
%m |
mm |
2 digit month | 12 | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME%. Zero filled. |
m |
month | 1 | Month, no leading zero. Note that the Time::Format code is ambiguous; it is the same as the code for the minute. | ||
?m |
month | 1 | Month, leading space if less than 10. Note that the Time::Format code is ambiguous; it is the same as the code for the minute. | ||
$year |
%Y |
yyyy |
4 digit year | 1999 | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME%, DateTimePlugin, SpreadSheetPlugin ( $FORMATTIME() ). |
$ye |
%y |
yy |
2 digit year | 99 | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME%, DateTimePlugin, SpreadSheetPlugin ( $FORMATTIME() ). |
$tz |
either "GMT" (if set to gmtime), or "Local" (if set to servertime) | GMT | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME% | ||
%Z |
tz |
Time zone abbreviation | GMT | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME% | |
$iso |
%Y-%m-%dT%H:%MZ |
ISO format timestamp | 2005-03-31T22:08Z | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME% | |
$rcs |
%Y/%m/%d %H:%M:%S |
RCS format timestamp | 2005/03/31 22:08:24 | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME% | |
$http |
E-mail & http format timestamp | Thu, 31 Mar 2005 22:08:24 GMT | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME% | ||
$epoch |
Seconds since the epoch | 1125594288 | Used by %DISPLAYTIME%, %GMTIME%, %SERVERTIME% (Dakar and later) | ||
$date |
Time stamp of last topic update | 31 Mar 2005 - 22:08 | Used by %SEARCH% format parameter. |
||
$isodate |
Time stamp of last topic update | 2005-03-31T22:08Z | Used by %SEARCH% format parameter. |
||
... |
... |
... |
... | ... | ... |
strftime()
equivalent format specifier (when there is one) and where these specifiers are used. Note that there are some incompatible usages among the sources that I could find: SpreadSheetPlugin, DateTimePlugin, and the built-in functions %DISPLAYTIME%, %GMTIME%, and %SERVERTIME%.
-- DavidBright - 06 Apr 2005
Wow, this is great. Now if we could just do something about this....
-- ThomasWeigert - 06 Apr 2005
The table now contains codes from three sources: TWiki, the POSIX strftime() function, and the CPAN:Time::Format module. CPAN:Time::Format uses formatting codes that (quoting from the module documentation): "are designed to be easy to remember and use, and to take up just as manu characters as the output time value whenever possible. [...] This module is for everyone who is weary of trying to remember strftime(3) 's arcane codes...." The table isn't quite complete, as there are some strftime() and CPAN:Time::Format codes that I didn't include; also, there is no guarantee that I haven't missed codes in use within TWiki.
So, where is this going? Here are my current thoughts on getting some more complete and consistent date/time formatting codes into use in TWiki: %
sign. If we want to use the strftime() codes, we could use a $
instead of %
to avoid the potential parsing ambiguity. This would also be more consistent with the other string replacement instances in TWiki.
"The current month is: Month"
would yield (today, assuming this is formatted exactly on the minute): "The current april i00: April". There are at least two ways of handling this: \Q
and \E
(or the end of the format string) is protected from substitution. So, the previous example format would be written: "\QThe current month is:\E Month"
$
. This has the advantage of being consistent with existing TWiki usage, but carries the disadvantage that it defeats one of the goals of the codes, which was to take up exactly as much space as the rendered text (whenever possible).
$epoch
(the number of seconds since 1st Jan 1970, useful for building unique URLs).
-- CrawfordCurrie - 01 Sep 2005
Yes, I've looked at that and thought of using it for CalendarPlugin. However, it doesn't allow for localization (as far as I can see), nor for times before the epoch. These are capabilities of the current plugin. However, I do think that the creation of the TWiki::Time module is a good thing. Perhaps it can be extended in the future to provide these capabilities.
-- DavidBright - 01 Sep 2005
Anything you can do to improve it would be most welcome. I started to, but was put off by the need (as I saw it) to import yet another CPAN dependency. I suppose I shouldn't have been, but it dropped below the radar after that. I'm not sure what other localisation is required. Month names, for example? Alternative calendars?
Interestingly enough I came across a real need for dates before the epoch. I wanted to build a demo of the FormQueryPlugin using my family tree as the database, and soon ran into problems.
-- CrawfordCurrie - 02 Sep 2005
http://koala.ilog.fr/twikiirc/bin/irclogger_log/twiki?date=2006-06-18,Sun&sel=36#l32
-- MartinCleaver - 18 Jun 2006
I realise this is an old topic revived by TWikiJanitor, but if anyone's going to have a look at this, it's worth reading some older topics as well, in particular SettingCorrectTimeZone and TimeZone which discuss showing local time (which can differ between users and should be configurable per-user). And if anyone is doing this, it would be great to include I18N so that the user can see a native language date/time format that is appropriate to their locale.
-- RichardDonkin - 15 Sep 2008
Also note that there are (at least?) two config parameters for setting the default format, and they use different syntaxes. E.g., to select the ISO format:
The first one (which is used by forms) doesn't appear in the$TWiki::cfg{JSCalendarContrib}{format} = '%Y-%m-%d'; $TWiki::cfg{DefaultDateFormat} = $year-$mo-$day';
configure
application and so was unknown to me until mentioned by Peter in DateFormatInForms.
Even so, those parameters don't cover all date displays: e.g., see my bug report at TWikibug:Item5606, "ActionTracker: ActionSearch not using DefaultDateFormat".
Related content: UseIsoDates.
-- SeanCMorgan - 16 Sep 2008