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.

27 lines (25 loc) • 782 B
import { systemTimeZone } from "../../internal/resolveLocale.js"; import { nowZonedDateTimeISO } from "../../internal/temporalCompat/clock.js"; // src/plain/get/getMonth.ts /** * Return the current month using the system timeZone. * * - Uses nowZonedDateTimeISO() to get current month in system timezone. * - Returns zero-padded string (e.g., "02"). * - Returns "" when system timezone is unavailable. * * @returns current month string (zero-padded) or "" on invalid * * @example getMonth() // "02" * @example getMonth() // "" (when system timeZone unavailable) */ function getMonth() { const timeZone = systemTimeZone(); if (!timeZone) return ""; try { return nowZonedDateTimeISO(timeZone).month.toString().padStart(2, "0"); } catch { return ""; } } export { getMonth };