# formatTime

Industry: Core

## Signature

```ts
formatTime(value: string, locale?: string | string[], options?: DateTimeFormatOptions): string
```

Return a localized string for a PlainTime ISO input using Intl options.

- Formats as Temporal's ECMA-402 PlainTime format (`PlainTime#toLocaleString`) does, through the runtime's `Intl.DateTimeFormat`. `era` and `timeZoneName` are ignored, so alone they get the hour, minute and second defaults.
- Accepts optional BCP 47 locale and Intl.DateTimeFormatOptions.
- Returns "" for invalid input, for a `dateStyle` (with or without `timeStyle`) and for only date fields, where `PlainTime#toLocaleString` throws a TypeError.
- **Compatibility:** before 1.16.0 `era` or `timeZoneName` alone returned `""`, `era` beside a time field added the era name, and a `dateStyle` beside `timeStyle` was ignored. Pass only `timeStyle` to keep the styled text.
- `options` null returns `""`, as ECMA-402's CoerceOptionsToObject rejects it. Any other non-object — a string, a number, a boolean — formats with the defaults, as `Intl.DateTimeFormat` does: CoerceOptionsToObject calls ToObject on it and the wrapper carries no recognised option. Only `null` and `undefined` are special-cased.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | ISO PlainTime string |
| `locale` | `string` \| `string[]` | optional BCP 47 locale identifier, or a preference list of tags (ECMA-402) |

## Options

**options**

optional Intl.DateTimeFormatOptions

Type: [`DateTimeFormatOptions`](/gmt/reference/types/DateTimeFormatOptions/).

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `…Intl.DateTimeFormatOptions` | — | — | Every field of [`DateTimeFormatOptions`](/gmt/reference/types/DateTimeFormatOptions/), as [ECMA-402](https://tc39.es/ecma402/#sec-createdatetimeformat) defines it. |

## Returns

localized time string or "" on invalid input

## Related types

- [`DateTimeFormatOptions`](/gmt/reference/types/DateTimeFormatOptions/)

## Examples

```ts
import { formatTime } from "@northguild/gmt/plain/format";

formatTime("14:30:00", "hi-IN", { timeStyle: "short" }) // "2:30 pm"
```

## Source

[plain/format/formatTime.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/plain/format/formatTime.ts)
