Format - Maple Help

Calendar

 Format
 format a Date or UTC Time object as a string
 Parse
 parse a string to a Date object with respect to a given format string

 Calling Sequence Format( d, fmt ) Parse( s, fmt )

Parameters

 d - Date; a Date object s - string; string to parse fmt - string; (optional) a format string

Options

 • locale : string; the name of a locale to use

Description

 • Dates (and Time objects) can be formatted to a string by using the Format( d, fmt ) command.
 • A string containing date information can be parsed to produce a corresponding Date object by using the Parse( s, fmt ) command.
 • The format string fmt is a string of free-form text with embedded formatting codes specified in the Unicode Technical Standard #35. Note that literal text in fmt must be quoted with single (forward) quotes (').
 • For an alternative way to provide format strings, see Calendar[VariantFormat].
 • The format string fmt is optional. Its default value is the string "yyyy-MM-dd'T'HH:mm:ss zzz".
 • Use the locale = loc option to control which locale formatting and parsing occurs in. The loc value should be a two-letter language code (E.g., "id" for Indonesian), optionally separated by an underscore character ("_") from a country variant indicates by using a two- or three-letter country code. (E.g., "fr_CA" for Canadian French.)
 • For some of the examples below to print correctly, you may need special fonts to be installed on your computer.

Examples

 > $\mathrm{with}\left(\mathrm{Calendar}\right):$
 > $s≔\mathrm{Format}\left(\mathrm{Today}\left(\right)\right)$
 ${s}{≔}{"2021-03-09T02:28:57 UTC"}$ (1)
 > $\mathrm{Parse}\left(s\right)$
 ${\mathrm{Date}}{}\left({2021}{,}{3}{,}{9}{,}{2}{,}{28}{,}{57}{,}{\mathrm{timezone}}{=}{"UTC"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (2)
 > $\mathrm{Format}\left(\mathrm{Today}\left(\right),"\text{'}The day of the week is \text{'}eeee"\right)$
 ${"The day of the week is Tuesday"}$ (3)
 > $s≔\mathrm{Format}\left(\mathrm{Today}\left(\right),"EEEE, MMMM dd, yyyy GG \text{'}at\text{'} hh:mm:ss a"\right)$
 ${s}{≔}{"Tuesday, March 09, 2021 AD at 02:28:57 AM"}$ (4)
 > $\mathrm{Parse}\left(s,"EEEE, MMMM dd, yyyy GG \text{'}at\text{'} hh:mm:ss a"\right)$
 ${\mathrm{Date}}{}\left({2021}{,}{3}{,}{9}{,}{2}{,}{28}{,}{57}{,}{\mathrm{timezone}}{=}{"UTC"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (5)
 > $t≔\mathrm{Format}\left(\mathrm{Now}\left(\mathrm{SystemUTCClock}\right)\right)$
 ${t}{≔}{"2021-03-09T02:28:57 UTC"}$ (6)

Note that the output of Parse is always a Date object; the source of the input string as a formatted Time object is unknown to the Parse command.

 > $\mathrm{Parse}\left(t\right)$
 ${\mathrm{Date}}{}\left({2021}{,}{3}{,}{9}{,}{2}{,}{28}{,}{57}{,}{\mathrm{timezone}}{=}{"UTC"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (7)

To use a locale different from the default locale, use the locale= option.

 > $\mathrm{Format}\left(\mathrm{Today}\left(\right),"EEEE, MMMM dd, yyyy GG, hh:mm:ss a",'\mathrm{locale}'="ja"\right)$
 ${"火曜日, 3月 09, 2021 西暦, 02:28:57 午前"}$ (8)
 > $\mathrm{Format}\left(\mathrm{Today}\left(\right),"EEEE, MMMM dd, yyyy GG \text{'}jam\text{'} hh:mm:ss a",'\mathrm{locale}'="id"\right)$
 ${"Selasa, Maret 09, 2021 M jam 02:28:57 AM"}$ (9)
 > $s≔\mathrm{Format}\left(\mathrm{Today}\left(\right),"EEEE, MMMM dd, yyyy GG \text{'}um\text{'} hh:mm:ss a",'\mathrm{locale}'="de"\right)$
 ${s}{≔}{"Dienstag, März 09, 2021 n. Chr. um 02:28:57 AM"}$ (10)
 > $\mathrm{Parse}\left(s,"EEEE, MMMM dd, yyyy GG \text{'}um\text{'} hh:mm:ss a",'\mathrm{locale}'="de"\right)$
 ${\mathrm{Date}}{}\left({2021}{,}{3}{,}{9}{,}{2}{,}{28}{,}{57}{,}{\mathrm{timezone}}{=}{"UTC"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (11)
 > $s≔\mathrm{Format}\left(\mathrm{Date}\left(-42,3,15,3,4,5\right),"EEEE, MMMM dd, yyyy GGGGGGG \text{'}jam\text{'} hh:mm:ss a",'\mathrm{locale}'="id"\right)$
 ${s}{≔}{"Kamis, Maret 15, 0043 SM jam 03:04:05 AM"}$ (12)
 > $\mathrm{Parse}\left(s,"EEEE, MMMM dd, yyyy GGGGGGG \text{'}jam\text{'} hh:mm:ss a",'\mathrm{locale}'="id"\right)$
 ${\mathrm{Date}}{}\left({-}{42}{,}{3}{,}{15}{,}{3}{,}{4}{,}{5}{,}{\mathrm{timezone}}{=}{"UTC"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (13)
 > 
 References

Compatibility

 • The Calendar[Format] and Calendar[Parse] commands were introduced in Maple 2019.