Documentation
    Preparing search index...

    Namespace DateTime

    Contains a set of helper functions to work with Date and Temporal APIs.

    Note that since Temporal API is still in TC 39 Draft phase, if you are going to work with these API, you will have to apply a polyfill, such as

    jscorlib is not providing polyfill as its implementation is not trivial.

    As this package as declared to be side-effectless, you should not see runtime errors caused by "missing dependencies" until you have consumed functions that have code path dependency on Temporal API.

    This module provides a more permissive parsing functionality for Date and Temporal APIs. Similar to date/time parsing in .NET, this package currently supports any of following "invariant" date/time expressions.

    • Date expression
      • yyyy-MM-dd
      • MM-dd-yyyy
      • yyyy-MMM-dd
      • yyyy-MMMM-dd
      • dd-MMM-yyyy (RFC 1123)
      • dd-MNMM-yyyy
      • Optionally, prepending or appending ddd is supported.
    • Time expression
      • HH:mm:ss.fffffffff
      • tt hh:mm:ss.fffffffff
      • hh:mm:ss.fffffffff tt
    • Time zone offset
      • +0:00
      • +00:00
      • +0000
      • Z (=+00:00)
      • GMT (=+00:00) (RFC 1123)
    • Time zone ID (Not supported by Date)
      • [tz]

    Refer to Custom date and time format strings for a list of explanations for the placeholders above.

    These expressions are combined in the following order, with optional whitespaces in between

    Date + Time [+ Time zone offset] [+ Time zone ID]

    Not all of the expressions above are mandatory. Besides, one or more sub-part of the date or time expression can be neglected. For example, the following date/time expression are all valid

    • 2001-10-5 -> 2021-10-5 00:00:00 Z
    • 2001-10-5 +8:00 -> 2021-10-4 16:00:00 Z
    • 2001-10 -> 2021-10-1 00:00:00 [local TZ]
    • 10:50Z -> [Today] 10:50:00 Z
    • 10:50 -> [Today] 10:50:00 [local TZ]
    • 10:50 [Asia/Shanghai] -> [Today] 10:50:00 +8:00 [Asia/Shanghai]

    However, at least either of the date or time expression should present. Expressions with only time zone ID / offset are considered invalid.

    Interfaces

    DateTimeParsingOptions

    Functions

    parseDate
    parseInstant
    parseZonedDateTime
    tryParseDate
    tryParseInstant
    tryParseZonedDateTime