# Class TimeFormatter

A helper class for formatting and parsing times.

#### Hierarchy (view full)

- SerializableBase<TimeFormatterProperties>
  - TimeFormatter

#### Implements

- TimeSettings

#####
Index

### Constructors

constructor

### Properties

defaultParseFormat
locale

### Accessors

defaultFormat

### Methods

_getSerializableProperties
_toPropertyDef
assignProperties
assignPropertiesAsync
finishAssignProperties
format
getDefault
getDefaults
getSerializableProperties
parse
toJSON

##
Constructors

### constructor

- new TimeFormatter(_properties?): TimeFormatter

- #### Parameters

  - `Optional`_properties: TimeFormatterProperties

  #### Returns TimeFormatter

  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/time!TimeFormatter.format.

Implementation of TimeSettings.defaultParseFormat

### locale

locale: string

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

##
Accessors

### defaultFormat

- get defaultFormat(): string

- The default format for formatting times. See utilities/format/time!TimeFormatter.format.

  #### Returns string

  Implementation of TimeSettings.defaultFormat

- set defaultFormat(value): void

- The default format for formatting times. See utilities/format/time!TimeFormatter.format.

  #### Parameters

  - value: string

  #### Returns void

  Implementation of TimeSettings.defaultFormat

##
Methods

### `Protected`_getSerializableProperties

- _getSerializableProperties(): PropertyDefs<TimeFormatterProperties>

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

  #### Returns PropertyDefs<TimeFormatterProperties>

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

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

    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(time): string

- Formats a time for display.

  #### Parameters

  - time: Time

    The time to format.

  #### Returns string

- format(format, time): string

- Formats a time for display.

  #### Parameters

  - format: string

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

    - ":" is treated as a literal character.
    - "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 TIME_SHORT.
  - time: Time

    The time to format.

  #### Returns string

- format(options, time): string

- Formats a time for display.

  #### Parameters

  - options: FormatOptions

    Options that control how the time is formatted.

  - time: Time

    The time to format.

  #### Returns string

### getDefault

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

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

  #### Type Parameters

  - K extends keyof TimeFormatterProperties

  #### Parameters

  - key: K

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

  #### Returns TimeFormatterProperties[K]

  Inherited from SerializableBase.getDefault

### getDefaults

- getDefaults(): TimeFormatterProperties

- Gets the object's default property values.

  #### Returns TimeFormatterProperties

  Inherited from SerializableBase.getDefaults

### getSerializableProperties

- getSerializableProperties(serializeMode?): PropertyDefs<TimeFormatterProperties>

- Returns the serializable properties.

  #### Parameters

  - serializeMode: SerializeMode = "all"

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

  #### Returns PropertyDefs<TimeFormatterProperties>

  Inherited from SerializableBase.getSerializableProperties

### parse

- parse(input): Time

- Parses a value into a Time object.

  #### Parameters

  - input: unknown

    The input to parse.

  #### Returns Time

  A Time object corresponding to the input. If unable to parse successfully, will return an invalid Time.

- parse(format, input): Time

- Parses a value into a Time object.

  #### Parameters

  - format: string | string[]

    See ParseOptions.format.

  - input: unknown

    The input to parse.

  #### Returns Time

  A Time object corresponding to the input. If unable to parse successfully, will return an invalid Time.

- parse(options, input): Time

- Parses a value into a Time object.

  #### Parameters

  - options: ParseOptions

    The options to use for parsing.

  - input: unknown

    The input to parse.

  #### Returns Time

  A Time object corresponding to the input. If unable to parse successfully, will return an invalid Time.

### toJSON

- toJSON(serializeMode?): TimeFormatterProperties

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

  Inherited from SerializableBase.toJSON