Calendar Package Updates in 2019 - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Information : Updates : Maple 2019 : updates/Maple2019/DateTime

Calendar Package Updates in 2019

 

Description

Formatting Dates and Times

Parsing Dates and Times

Description

• 

The Calendar package has new commands for parsing and formatting Date and Time objects.

Formatting Dates and Times

• 

Use the Calendar:-Format command or the Calendar:-VariantFormat command to format a Date or UTC Time object as a string. You can do this in a locale-sensitive way by using the locale option.

• 

Codes for formatting and parsing are specified according to the Unicode Technical Standard #35, "Unicode Locale Data Markup Language (LDML)", Part 4 (Dates).

with( Calendar ):

Format( Today() );

2020-03-05T02:37:53 UTC

(1)

Format( Today(), 'locale' = "fr" );

2020-03-05T02:37:53 UTC

(2)

Format( Today(), "yyyy.MM.dd G 'at' HH:mm:ss zzz" );

2020.03.05 CE at 02:37:53 UTC

(3)

Format( Today(), "yyyy.MM.dd G 'um' HH:mm:ss zzz", 'locale' = "de" );

2020.03.05 n. Chr. um 02:37:53 UTC

(4)

Format( Now( SystemUTCClock ), "K:mm a, z", 'locale' = "ja" );

2:37 午前, UTC

(5)

Format( Now( SystemUTCClock ), "hh 'o''clock' a, zzzz" );

02 o'clock AM, GMT

(6)
• 

You can use a different (printf-like) formatting string by using the command VariantFormat.

• 

Unlike the similar command FormatTime in the StringTools package, the Calendar:-VariantFormat command supports the locale option, allowing you to format dates and times in a locale-sensitive way. Moreover, the Calendar package commands work directly with Date and UTC Time objects.

VariantFormat( Today(), "%c" );

Thu M03 05 02:37:53 2020

(7)

VariantFormat( Today(), "%c", 'locale' = "id" );

Kam Mar 05 02:37:53 2020

(8)

fmt := "EEEE, MMMM dd, yyyy GG, hh:mm:ss a":

DocumentTools:-Tabulate( map( loc -> Format( Today(), fmt, ':-locale' = loc ), << "en", "fr", "de" > | < "ks", "ja", "ko" >> ) ):

Thursday, March 05, 2020 AD, 02:37:53 AM

برؠسوار, مارٕچ ۰۵, ۲۰۲۰ اے ڈی, ۰۲:۳۷:۵۳ AM

jeudi, mars 05, 2020 ap. J.-C., 02:37:53 AM

木曜日, 3 05, 2020 西暦, 02:37:53 午前

Donnerstag, März 05, 2020 n. Chr., 02:37:53 AM

목요일, 3 05, 2020 AD, 02:37:53 오전

 

Parsing Dates and Times

• 

As for formatting, there are new commands to parse dates in strings. These are Parse and VariantParse, corresponding to Format and VariantFormat, respectively.

• 

Both Parse and VariantParse support the locale option.

s := Format( Today(), "EEEE, MMMM dd, yyyy GG, hh:mm:ss a", 'locale' = "id" );

sKamis, Maret 05, 2020 M, 02:37:53 AM

(9)

Parse( s, "EEEE, MMMM dd, yyyy GG, hh:mm:ss a", 'locale' = "id" );

Date2020&comma;3&comma;5&comma;2&comma;37&comma;53&comma;timezone&equals;UTC&comma;coefficient&equals;1

(10)

s := VariantFormat( Today(), "%c", 'locale' = "de" );

sDo. März 05 02:37:53 2020

(11)

VariantParse( s, "%c", 'locale' = "de" );

Date2020&comma;3&comma;5&comma;2&comma;37&comma;53&comma;timezone&equals;UTC&comma;coefficient&equals;1

(12)

 

See Also

Calendar

Calendar:-Format

Calendar:-Parse

Calendar:-VariantFormat

Calendar:-VariantParse

Date

StringTools:-FormatTime

StringTools:-ParseTime

Time