Calendar Package Updates in 2019
Description
Formatting Dates and Times
Parsing Dates and Times
The Calendar package has new commands for parsing and formatting Date and Time objects.
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() );
2025-03-24T10:27:34 UTC
Format( Today(), 'locale' = "fr" );
Format( Today(), "yyyy.MM.dd G 'at' HH:mm:ss zzz" );
2025.03.24 AD at 10:27:34 UTC
Format( Today(), "yyyy.MM.dd G 'um' HH:mm:ss zzz", 'locale' = "de" );
2025.03.24 n. Chr. um 10:27:34 UTC
Format( Now( SystemUTCClock ), "K:mm a, z", 'locale' = "ja" );
10:27 午前, UTC
Format( Now( SystemUTCClock ), "hh 'o''clock' a, zzzz" );
10 o'clock AM, Coordinated Universal Time
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" );
Mon Mar 24 10:27:34 2025
VariantFormat( Today(), "%c", 'locale' = "id" );
Sen Mar 24 10:27:34 2025
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" >> ) ):
Monday, March 24, 2025 AD, 10:27:34 AM
ژٔندرٕروار, مارٕچ ۲۴, ۲۰۲۵ اے ڈی, ۱۰:۲۷:۳۴ AM
lundi, mars 24, 2025 ap. J.-C., 10:27:34 AM
月曜日, 3月 24, 2025 西暦, 10:27:34 午前
Montag, März 24, 2025 n. Chr., 10:27:34 AM
월요일, 3월 24, 2025 AD, 10:27:34 오전
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" );
s≔Senin, Maret 24, 2025 M, 10:27:34 AM
Parse( s, "EEEE, MMMM dd, yyyy GG, hh:mm:ss a", 'locale' = "id" );
<Date: 2025-03-24T10:27:34 GMT>
s := VariantFormat( Today(), "%c", 'locale' = "de" );
s≔Mo. März 24 10:27:35 2025
VariantParse( s, "%c", 'locale' = "de" );
<Date: 2025-03-24T10:27:35 GMT>
See Also
Calendar
Calendar:-Format
Calendar:-Parse
Calendar:-VariantFormat
Calendar:-VariantParse
Date
StringTools:-FormatTime
StringTools:-ParseTime
Time
Download Help Document