UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

21 lines (19 loc) • 687 B
import { nowInstant } from "../../internal/temporalCompat/clock.js"; import { isoYearString } from "../../internal/isoYearString.js"; // src/utc/get/getUtcYear.ts /** * Return the current year from UTC as a zero-padded string. * * - Uses nowInstant() converted to UTC zoned date time. * - Returns zero-padded string to 4 digits. * - A year outside 0000–9999 is written with a sign and six digits (`+010000`, `-000005`), as * Temporal writes it at the head of a date. * * @returns current year string (zero-padded to 4 digits) * * @example getUtcYear() // "2024" */ function getUtcYear() { return isoYearString(nowInstant().toZonedDateTimeISO("UTC").year); } export { getUtcYear };