Myrddin: Formatting

Date and Time Formatting

Formatting in libdate is done through the standard formatting functionality, and there are actually no functions exposed by libdate. Instead, you would write something like:

Custom formatting is done with a format option passed to std.format that looks like f=dateformat. The format strings used resemble the strings provided in strptime. Any characters preceded with a '%' are format characters, otherwise they are copied to the output stream directly.

The format strings used to control formatting are also used to control parsing.

An example would look like:

Date and Time Formatting

Both parsing and formatting use the same format strings. The modifiers that are supported by libdate are listed below.

When possible, the default format verbs D, d, or t should be used for formatting, and the default constants Datefmt, Datetimefmt, or Timefmt should be used for parsing.

Char Meaning
%a Abbreviated day of week: Mon, Tues, etc
%A Full day of week: Monday, Tuesday, Wednesday, etc
%b Abbreviated month of year: Jan, Feb, Mar, etc.
%B Full month of year: January, February, etc
%c Short for %Y-%m-%d %H:%M:%S %z (ISO 8601)
%C Century number of year, as two digit integer.
%d Day of month as a decimal number, 00 to 31.
%D Short for "%m/%d/%y (wtf america)"
%e Same as d, but space padded instead of zero padded.
%F Short for ISO 8601 date format %Y-%m-%d
%h Same as '%b'.
%H Hour number using the 24 hour clock, zero padded.
%I Hour number using the 12 hour clock, zero padded.
%j Day of year as a decimal number, 001 to 366.
%k Hour number using the 24 hour clock, space padded.
%l Hour number using the 12 hour clock, space padded.
%m The month number, zero padded.
%M The minute number, zero padded.
%p AM or PM, according to the time provided.
%P am or pm, according to the time provided.
%r 12 hour time: %I:%M %p
%R 24 hour time: %H:%M
%s The number of seconds since the Epoch
%S The second number, zero padded. 0 to 60.
%T The time including seconds in 24 hour format.
%u The day of the week in decimal, 0 to 7.
%x The date without the time. Same as %F
%X The date with the time. Same as %c
%y The final two digits of year.
%Y The full year, including century. BC dates are negative.
%z Timezone offset.
%Z Timezone name or abbreviation. Offset if this is not available.
%% A literal '%'