A helper class for formatting and parsing dates.

Hierarchy (view full)

Implements

Constructors

Properties

defaultParseFormat: string

Either a single format, or one of several possible formats that the input is expected to be in. If specified, the input must exactly match. The syntax is the same as for utilities/format/date!DateFormatter.format.

locale: string

The locale to use when formatting & parsing the number. If not specified, the current locale is used (see locale module).

Accessors

  • get parseTimeZone(): string
  • The time zone of the date being parsed.

    Returns string

  • set parseTimeZone(value): void
  • Parameters

    • value: string

    Returns void

  • get timeZone(): string
  • The time zone of the date being formatted.

    Returns string

  • set timeZone(value): void
  • Parameters

    • value: string

    Returns void

Methods

  • Sets the properties for this item.

    This version will also await any asynchronous logic that is needed to set the properties.

    Parameters

    • properties: Partial<DateFormatterProperties>

      A plain object containing property values to set, keyed by property name.

    Returns Promise<void>

  • Waits for all deserialization logic initiated thus far to finish, whether invoked by passing properties into the constructor, or by invoking assignProperties() or assignPropertiesAsync().

    Returns Promise<void>

  • Formats a date for display.

    Parameters

    • date: Date

      The date to format.

    Returns string

  • Formats a date for display.

    Parameters

    • format: string

      The format for presenting dates. One of the utilities/format/formats!DateFormat constants, or a custom format string. The format string syntax is similar to https://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx|this, with the following exceptions:

      • "/", and ":" are treated as literal characters.
      • "y" is treated as "yy", and "yyy" is treated as "yyyy".
      • "z" and "zz" and "zzz" are treated as the UTC offset
      • "t" is treated the same as "tt".
      • "F", "FF", "FFF" etc. will behave the same as "f", "ff", "fff", etc. Additionally, a maximum of 3 digits (milliseconds) is supported. Longer formatters like "fffff" are truncated to 3 digits, rather than padded with zeros.
      • "K" is not supported at all and will be ignored. If not specified, it will default to DATE_TIME_SHORT.
    • date: Date

      The date to format.

    Returns string

  • Formats a date for display.

    Parameters

    • options: FormatOptions

      Options that control how the date is formatted.

    • date: Date

      The date to format.

    Returns string

  • Parses a value into a Date object. The input is assumed to be in local time, unless it's a timestamp..

    Parameters

    • input: unknown

      The input to parse. Numbers are treated as UNIX timestamps (always assumed to be UTC unless timezone is specified).

    Returns Date

    A Date object corresponding to the input, which might be an Invalid Date (i.e. getTime() will be NaN).

  • Parses a value into a Date object. The input is assumed to be in local time, unless it's a timestamp..

    Parameters

    • format: string | string[]
    • input: unknown

      The input to parse. Numbers are treated as UNIX timestamps (always assumed to be UTC unless timezone is specified).

    Returns Date

    A Date object corresponding to the input, which might be an Invalid Date (i.e. getTime() will be NaN).

  • Parses a value into a Date object. The input is assumed to be in local time, unless it's a timestamp.

    Parameters

    • options: ParseOptions

      The options to use for parsing.

    • input: unknown

      The input to parse. Numbers are treated as UNIX timestamps (always assumed to be UTC unless timezone is specified).

    Returns Date

    A Date object corresponding to the input, which might be an Invalid Date (i.e. getTime() will be NaN).

  • Parses a value into a Date object. The input is assumed to be in UTC.

    Parameters

    • input: unknown

      The input to parse. Numbers are treated as UNIX timestamps (always assumed to be UTC even if timezone is specified).

    Returns Date

    A Date object corresponding to the input, which might be an Invalid Date (i.e. getTime() will be NaN).

  • Parses a value into a Date object. The input is assumed to be in UTC.

    Parameters

    • format: string | string[]
    • input: unknown

      The input to parse. Numbers are treated as UNIX timestamps (always assumed to be UTC even if timezone is specified).

    Returns Date

    A Date object corresponding to the input, which might be an Invalid Date (i.e. getTime() will be NaN).

  • Parses a value into a Date object. The input is assumed to be in UTC.

    Parameters

    • options: ParseOptions

      The options to use for parsing.

    • input: unknown

      The input to parse. Numbers are treated as UNIX timestamps (always assumed to be UTC even if timezone is specified).

    Returns Date

    A Date object corresponding to the input, which might be an Invalid Date (i.e. getTime() will be NaN).