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