@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) • 791 B
JavaScript
import { systemTimeZone } from "../../internal/resolveLocale.js";
import { nowPlainDateTimeISO } from "../../internal/temporalCompat/clock.js";
// src/plain/get/getSecond.ts
/**
* Return the current second using the system timeZone.
*
* - Uses nowPlainDateTimeISO() to get current second in system timezone.
* - Returns zero-padded string (e.g., "45").
* - Returns "" when system timezone is unavailable.
*
* @returns current second string (zero-padded) or "" on invalid
*
* @example getSecond() // "00"
* @example getSecond() // "" (when system timeZone unavailable)
*/
function getSecond() {
const timeZone = systemTimeZone();
if (!timeZone) return "";
try {
return nowPlainDateTimeISO(timeZone).second.toString().padStart(2, "0");
} catch {
return "";
}
}
export { getSecond };