formatYearMonth
Signature
Section titled “Signature”formatYearMonth(value: string, locale?: string | string[], options?: DateTimeFormatOptions): stringReturn a localized string for a year-month (YYYY-MM) using Intl options.
- Formats as Temporal’s ECMA-402 PlainYearMonth format does: only
year,monthanderaare kept, at noon UTC on the first of the month. - Gregorian rule (GMT). Always formats through the Gregorian calendar, which names the same year and month as the ISO one. ICU formats
calendar: "iso8601"without the locale’s year-month pattern (Node prints"1970 "with no month name), andPlainYearMonth#toLocaleStringthrows for a calendar mismatch. A-u-ca-subtag inlocaleis overridden. With acalendaroption, the calendar Intl resolves must begregoryoriso8601, otherwise"". Intl ignores an unsupported value and uses the locale’s default, so{ calendar: "foo" }gives"10/2026"in en-US and""in th-TH (Buddhist). dateStyle. The year and month widths are the locale’s owndateStyledate pattern’s, as ECMA-402 (AdjustDateTimeStyleFormat) and nativePlainYearMonth#toLocaleStringtake them: en-USshortis10/26, de-DEmedium10/2026and zh-CNlong2026/10. Polyfill 0.5.1 maps each style to fixed widths instead, so itstoLocaleStringprintsOkt. 2026for de-DEmedium.- A
day,weekday, time field ortimeZoneNameis dropped; only those fields with noyearormonthgive"", excepttimeZoneName, which falls back to the defaults. Anerais kept. - A year at or before 0 prints the Gregorian era year (
0000is year 1,-000001is year 2) with no era unlesserais asked for, asformatDatedoes. - Returns
""for invalid input, atimeStyle, invalid options,nulloptions or an ill-formed locale.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO year-month string |
locale | string | string[] | optional BCP 47 locale identifier (default: runtime default), or a preference list of tags (ECMA-402) |
Options
Section titled “Options”options
optional Intl.DateTimeFormatOptions
Type: DateTimeFormatOptions.
| Option | Type | Default | Description |
|---|---|---|---|
…Intl.DateTimeFormatOptions | — | — | Every field of DateTimeFormatOptions, as ECMA-402 defines it. |
Returns
Section titled “Returns”localized year-month string or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { formatYearMonth } from "@northguild/gmt/plain/format";
formatYearMonth("2026-10", "en-US") // "10/2026"Source
Section titled “Source”Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else:© 2026 NorthGuild, all rights reserved.