Temporal templates
The functions Timestamp.Parse
, Date.Parse
and Time.Parse
will parse the corresponding type from a string using a template.
For example:
Timestamp.Parse("2018-02-01 01:02","yyyy-MM-dd H:m")
Date and time templates are specified by letters representing the components of a date or time.
The following patterns are supported:
d | day of month |
D | day of year |
M | month of year (7, 07, Jul, July) |
y | year |
Y | week based year, see java doc for more info. |
w | week of week based year (1-53) |
e | day of week (2, Tue, Tuesday) |
H | hour of day (0-23) |
K | hour of day (0-11) |
m | minute of hour |
s | second of minute |
S | fraction of second |
a | am or pm |
' | escape for text (‘foo’, ‘bar’) |
When repeated, these characters indicate a minimum number of characters the string should match.
-
MMM
parses short month names (Jan, Feb) andMMMM
parses full month names (January, February). -
yy
parses as the last two digits of a year with a base year of 2000 (18 parses as 2018, 95 parses as 2095). -
e
parses day of week (1-7),eee
parses short week day names (Mon, Tue) andeeee
parses full week day names (Monday, Tuesday).
Raw follows java conventions for date templates see java documentation for more info.
Examples
-
ISO 8601 date:
Date.Parse("2018-02-01", "yyyy-MM-dd")
-
ISO 8601 ordinal date:
Date.Parse("2019-062", "yyyy-DDD")
-
ISO 8601 week date:
Date.Parse("2019-W01-1", "YYYY-'W'ww-e")
-
ISO 8601 timestamp:
Timestamp.Parse("2018-02-01T01:02:03.004","yyyy-MM-dd'T'H:m:s.SSS")
-
RFC 1123 timestamp:
Timestamp.Parse("Wed, 09 Dec 2015 18:59:42", "eee, dd MMM yyyy H:m:s")