Getting the Current Date and Time
Use these functions when you need “now” in a specific shape. They are the starting point for almost every other operation — arithmetic, comparison, formatting.
Get the current local date or datetime
Section titled “Get the current local date or datetime”import { getNow, getToday } from "@northguild/gmt";
getToday(); // "2024-03-15" — current date in the system timezonegetNow(); // "2024-03-15T14:30:45" — current datetime in the system timezoneBoth resolve “now” in the system timezone. For deterministic results regardless of the host machine’s timezone, use the zoned variants with an explicit zone.
Get the current UTC date or datetime
Section titled “Get the current UTC date or datetime”import { getUtcToday, getUtcNow } from "@northguild/gmt/utc";
getUtcToday(); // "2024-03-15"getUtcNow(); // "2024-03-17T14:30:45Z"Get the current Unix timestamp
Section titled “Get the current Unix timestamp”import { getUnixNow, getUnixTimeMs } from "@northguild/gmt/unix";
getUnixNow(); // 1710504645 — seconds since epochgetUnixTimeMs(); // 1710504645000 — milliseconds since epochgetUnixNow returns seconds (the Unix convention). Use getUnixTimeMs when
you need milliseconds — 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-15T10:30:45"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(); // ["America/New_York", "Europe/London", ...] — ~422 entriesgetTimeZones() returns every IANA zone the runtime’s ICU data knows about. The
count varies by runtime.
Using Temporal directly
Section titled “Using Temporal directly”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 timeTemporal.Now.plainDateISO(); // Temporal.PlainDate — system timezoneTemporal.Now.plainDateTimeISO(); // Temporal.PlainDateTime — system timezoneTemporal.Now.zonedDateTimeISO("America/New_York"); // Temporal.ZonedDateTimeGMT re-exports Temporal from @northguild/gmt if you don’t want to depend on the
polyfill directly.
See also
Section titled “See also”- Plain Arithmetic — adding, subtracting, and diffing dates
- Zoned Operations — “now” in a specific zone
getNowreferencegetZonedNowreferencegetUnixNowreference