Service for formatting date and time values.

Hierarchy

  • DateTimeFormatter

Methods

Methods

  • Format the given date as the given type.

    Note
    If a string is supplied to the date parameter, it may be converted to a Date object before formatting. Note that, unless the string includes date, time, and timezone in an unambiguous format—like '2022-05-23T00:00:00.000Z'—this may have unexpected consequences.

    For example, calling DateTimeFormatter.format('2022-05-23', 'time') may very well return a nicely formatted time, but the value will obviously be nonsense, as there was no time data in the string provided in the first place.

    Returns

    A string representation of the date.

    Parameters

    • date: string | Date

      The date to format.

    • options: DateTimeType | DateTimeFormatterOptions

      Either a string specifying the type to format the date as, or a DateTimeFormatterOptions object.

    Returns string