node_24hr_time_resolver
v1.0.3
Published
Determine if the current system time format is 12hr or 24hr
Readme
Node24HrTimeResolver
Simple package to determine if the system time format is 12-hour or 24-hour. Works on Windows, MacOS, Linux (Desktop Environments) using Node.js.
When called in a browser or Linux server (headless environment) a fallback is provided by looking up the user's locale and using that to determine the time format for that region.
This module is written in TypeScript and ESM.
Installation
npm install node_24hr_time_resolverUsage
Boolean Check for 12 or 24 Hour Format: Determine if the system is using 12-hour or 24-hour time format.
is12Hr()returnstrueif the system is using 12-hour time format, otherwisefalse.is24Hr()returnstrueif the system is using 24-hour time format, otherwisefalse.
import { is24Hr, is12Hr } from 'node_24hr_time_resolver';
// If the system is using 24-hour time format, this will be true
is24Hr()
// If the system is using 12-hour time format, this will be true
is12Hr()
You can also get the format as a string ('12hr' or '24hr'):
Check if the system is using 12-hour or 24-hour time format:
determineSystemTimeFormat() returns either '12hr' or '24hr' depending on the system time format.
import determineSystemTimeFormat from 'node_24hr_time_resolver';
const timeFormat: "12hr" | "24hr" = determineSystemTimeFormat();
if (timeFormat === '24hr') {
console.log('The system is using 24-hour time format.');
} else if (timeFormat === '12hr') {
console.log('The system is using 12-hour time format.');
}