@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) • 714 B
JavaScript
import { nowInstant } from "../../internal/temporalCompat/clock.js";
import { isoYearString } from "../../internal/isoYearString.js";
// src/unix/get/getUnixYear.ts
/**
* Return the current year from the Unix timestamp in 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 getUnixYear() // "2024"
*/
function getUnixYear() {
return isoYearString(nowInstant().toZonedDateTimeISO("UTC").year);
}
export { getUnixYear };