DateTimeLocale.format

Format the given Time value into the provided output, using the specified layout. The layout can be a generic variant or a custom one, where generics are indicated via a single character:

<pre> "t" = 7:04 "T" = 7:04:02 PM "d" = 3/30/2009 "D" = Monday, March 30, 2009 "f" = Monday, March 30, 2009 7:04 PM "F" = Monday, March 30, 2009 7:04:02 PM "g" = 3/30/2009 7:04 PM "G" = 3/30/2009 7:04:02 PM "y" "Y" = March, 2009 "r" "R" = Mon, 30 Mar 2009 19:04:02 GMT "s" = 2009-03-30T19:04:02 "u" = 2009-03-30 19:04:02Z </pre>

For the US locale, these generic layouts are expanded in the following manner:

<pre> "t" = "h:mm" "T" = "h:mm:ss tt" "d" = "M/d/yyyy" "D" = "dddd, MMMM d, yyyy" "f" = "dddd, MMMM d, yyyy h:mm tt" "F" = "dddd, MMMM d, yyyy h:mm:ss tt" "g" = "M/d/yyyy h:mm tt" "G" = "M/d/yyyy h:mm:ss tt" "y" "Y" = "MMMM, yyyy" "r" "R" = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'" "s" = "yyyy'-'MM'-'dd'T'HH':'mm':'ss" "u" = "yyyy'-'MM'-'dd' 'HH':'mm':'ss'Z'" </pre>

Custom layouts are constructed using a combination of the character codes indicated on the right, above. For example, a layout of "dddd, dd MMM yyyy HH':'mm':'ss zzzz" will emit something like this:

Monday, 30 Mar 2009 19:04:02 -08:00

Using these format indicators with Layout (Stdout etc) is straightforward. Formatting integers, for example, is done like so:

Stdout.formatln ("{:u}", 5);
Stdout.formatln ("{:b}", 5);
Stdout.formatln ("{:x}", 5);

Formatting date/time values is similar, where the format indicators are provided after the colon:

Stdout.formatln ("{:t}", Clock.now);
Stdout.formatln ("{:D}", Clock.now);
Stdout.formatln ("{:dddd, dd MMMM yyyy HH:mm}", Clock.now);
  1. char[] format(char[] output, Time dateTime, cstring layout)
  2. void format(size_t delegate(cstring) output, Time dateTime, cstring layout)
    struct DateTimeLocale
    void
    format
    (
    scope size_t delegate output
    ,,)

Meta