@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.
25 lines (23 loc) • 716 B
JavaScript
import { systemTimeZone } from "../../internal/resolveLocale.js";
import { nowZonedDateTimeISO } from "../../internal/temporalCompat/clock.js";
// src/plain/get/getNow.ts
/**
* Return the current local PlainDateTime as an ISO string using the system timeZone.
*
* - Uses nowZonedDateTimeISO() to get current time in system timezone.
* - Returns "" when system timezone is unavailable.
*
* @returns ISO 8601 PlainDateTime string or "" on error
*
* @example getNow() // "2024-03-15T14:30:45" (current time)
*/
function getNow() {
const timeZone = systemTimeZone();
if (!timeZone) return "";
try {
return nowZonedDateTimeISO(timeZone).toPlainDateTime().toString();
} catch {
return "";
}
}
export { getNow };