# Class DateFormatter

A helper class for formatting and parsing dates.

#### Hierarchy (view full)

- SerializableBase<DateFormatterProperties>
  - DateFormatter

#### Implements

- DateSettings

#####
Index

### Constructors

constructor

### Properties

defaultParseFormat
locale

### Accessors

defaultFormat
parseTimeZone
timeZone

### Methods

_getSerializableProperties
_toPropertyDef
assignProperties
assignPropertiesAsync
finishAssignProperties
format
getDefault
getDefaults
getSerializableProperties
parse
parseUtc
toJSON

##
Constructors

### constructor

- new DateFormatter(_properties?): DateFormatter

- #### Parameters

  - `Optional`_properties: DateFormatterProperties

  #### Returns DateFormatter

  Inherited from SerializableBase.constructor

##
Properties

### defaultParseFormat

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.

Implementation of DateSettings.defaultParseFormat

### locale

locale: string

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

##
Accessors

### defaultFormat

- get defaultFormat(): string

- The default format for formatting dates. See utilities/format/date!DateFormatter.format.

  #### Returns string

  Implementation of DateSettings.defaultFormat

- set defaultFormat(value): void

- The default format for formatting dates. See utilities/format/date!DateFormatter.format.

  #### Parameters

  - value: string

  #### Returns void

  Implementation of DateSettings.defaultFormat

### parseTimeZone

- get parseTimeZone(): string

- The time zone of the date being parsed.

  #### Returns string

- set parseTimeZone(value): void

- #### Parameters

  - value: string

  #### Returns void

### timeZone

- get timeZone(): string

- The time zone of the date being formatted.

  #### Returns string

- set timeZone(value): void

- #### Parameters

  - value: string

  #### Returns void

##
Methods

### `Protected`_getSerializableProperties

- _getSerializableProperties(): PropertyDefs<DateFormatterProperties>

- The property keys and their metadata that are used to implement serializing and deserializing the class instance.

  #### Returns PropertyDefs<DateFormatterProperties>

  Overrides SerializableBase._getSerializableProperties

### `Protected`_toPropertyDef

- _toPropertyDef<T>(def): PropertyDef<T>

- Converts the value to a PropertyDef object.

  #### Type Parameters

  - T

  #### Parameters

  - def: PropertyDefSerializeMode | PropertyDefSerializeMode[] | PropertyDef<T>

    The value to convert.

  #### Returns PropertyDef<T>

  Inherited from SerializableBase._toPropertyDef

### assignProperties

- assignProperties(properties): void

- Sets the properties for this item.

  #### Parameters

  - properties: Partial<DateFormatterProperties>

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

  #### Returns void

  Inherited from SerializableBase.assignProperties

### assignPropertiesAsync

- assignPropertiesAsync(properties): Promise<void>

- 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>

  Inherited from SerializableBase.assignPropertiesAsync

### finishAssignProperties

- finishAssignProperties(): 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>

  Inherited from SerializableBase.finishAssignProperties

### format

- format(date): string

- Formats a date for display.

  #### Parameters

  - date: Date

    The date to format.

  #### Returns string

- format(format, date): 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

- format(options, date): 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

### getDefault

- getDefault<K>(key): DateFormatterProperties[K]

- Gets the default value of an object's property.

  #### Type Parameters

  - K extends keyof DateFormatterProperties

  #### Parameters

  - key: K

    The property of the object for which to get the default value.

  #### Returns DateFormatterProperties[K]

  Inherited from SerializableBase.getDefault

### getDefaults

- getDefaults(): DateFormatterProperties

- Gets the object's default property values.

  #### Returns DateFormatterProperties

  Inherited from SerializableBase.getDefaults

### getSerializableProperties

- getSerializableProperties(serializeMode?): PropertyDefs<DateFormatterProperties>

- Returns the serializable properties.

  #### Parameters

  - serializeMode: SerializeMode = "all"

    Optional. If specified, only properties that support the given serialization mode will be returned.

  #### Returns PropertyDefs<DateFormatterProperties>

  Inherited from SerializableBase.getSerializableProperties

### parse

- parse(input): Date

- 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).

- parse(format, input): Date

- 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[]

    See ParseOptions.format.

  - 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).

- parse(options, input): Date

- 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).

### parseUtc

- parseUtc(input): Date

- 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).

- parseUtc(format, input): Date

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

  #### Parameters

  - format: string | string[]

    See ParseOptions.format.

  - 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).

- parseUtc(options, input): Date

- 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).

### toJSON

- toJSON(serializeMode?): DateFormatterProperties

- Returns a serializable representation of the item.

  #### Parameters

  - serializeMode: SerializeMode = "all"

    If specified, only properties that are appropriate for the given mode are returned. Otherwise, all properties will be serialized.

  #### Returns DateFormatterProperties

  Inherited from SerializableBase.toJSON