Skip to content

Getting Current Date / Time

  • The core functions, which every industry uses.

Use these functions when you need “now” in a specific shape. They are the starting point for almost every other operation — arithmetic, comparison, formatting.

import { getNow, getToday } from "@northguild/gmt";
getToday(); // "2024-03-15" — current date in the system timezone
getNow(); // "2024-03-15T14:30:45.123456789" — current datetime in the system timezone

Both resolve “now” in the system timezone. For deterministic results regardless of the host machine’s timezone, use the zoned variants with an explicit zone.

import { convertUtcToPlainDate, getUtcNow } from "@northguild/gmt/utc";
getUtcNow(); // "2024-03-15T18:30:45.123456789Z"
convertUtcToPlainDate(getUtcNow()); // "2024-03-15" — the current date in UTC

There is no separate “UTC today” accessor: convertUtcToPlainDate takes the date of a UTC instant, in UTC unless you pass { timeZone }.

import { getUnixNow } from "@northguild/gmt/unix";
getUnixNow(); // 1710527445123 — milliseconds since epoch
getUnixNow({ epochUnit: "seconds" }); // 1710527445 — seconds since epoch

getUnixNow returns milliseconds unless you pass { epochUnit: "seconds" }. Name the unit the consumer expects — and be consistent: mixing the two is a common source of 1000x errors.

Get the current time in a specific timezone

Section titled “Get the current time in a specific timezone”
import { getZonedNow, getZonedToday } from "@northguild/gmt/zoned";
getZonedNow("America/New_York"); // "2024-03-15T14:30:45.123-04:00[America/New_York]"
getZonedToday("Asia/Tokyo"); // "2024-03-16"

Get the system timezone and the list of all IANA zones

Section titled “Get the system timezone and the list of all IANA zones”
import { getSystemTimeZone, getTimeZones } from "@northguild/gmt/zoned";
getSystemTimeZone(); // "America/New_York"
getTimeZones(); // ["Africa/Abidjan", "Africa/Accra", ...] — 418 entries on Node.js 24

getTimeZones() returns every IANA zone the runtime’s ICU data knows about. The count varies by runtime.

When you need the current value as a Temporal object for further manipulation (rather than a string), use Temporal.Now directly:

import { Temporal } from "@js-temporal/polyfill";
Temporal.Now.instant(); // Temporal.Instant — absolute point in time
Temporal.Now.plainDateISO(); // Temporal.PlainDate — system timezone
Temporal.Now.plainDateTimeISO(); // Temporal.PlainDateTime — system timezone
Temporal.Now.zonedDateTimeISO("America/New_York"); // Temporal.ZonedDateTime

GMT re-exports Temporal from @northguild/gmt if you don’t want to depend on the polyfill directly.