Skip to main content
Enhanced MS exports time constants that represent common durations in milliseconds. These constants are useful for calculations and comparisons.

Time

An object containing time unit constants in PascalCase.
const Time = {
  Nanosecond: 0.000_001,
  Microsecond: 0.001,
  Millisecond: 1,
  Second: 1_000,
  Minute: 60_000,
  Hour: 3_600_000,
  Day: 86_400_000,
  Week: 604_800_000,
  Month: 2_628_000_000,
  Year: 31_536_000_000,
  Decade: 315_360_000_000,
  Century: 3_153_600_000_000,
  Millennium: 31_536_000_000_000,
} as const;

Properties

Nanosecond
number
One nanosecond in milliseconds.
Microsecond
number
One microsecond in milliseconds.
Millisecond
number
default:1
One millisecond.
Second
number
default:1000
One second (1,000 milliseconds).
Minute
number
default:60000
One minute (60,000 milliseconds).
Hour
number
default:3600000
One hour (3,600,000 milliseconds).
Day
number
default:86400000
One day (86,400,000 milliseconds). Based on 24 hours.
Week
number
default:604800000
One week (604,800,000 milliseconds). Based on 7 days.
Month
number
default:2628000000
One month (2,628,000,000 milliseconds). Based on 28 days as a standard month length.
Year
number
default:31536000000
One year (31,536,000,000 milliseconds). Based on 365 days.
Decade
number
default:315360000000
One decade (315,360,000,000 milliseconds). Based on 10 years.
Century
number
default:3153600000000
One century (3,153,600,000,000 milliseconds). Based on 100 years.
Millennium
number
default:31536000000000
One millennium (31,536,000,000,000 milliseconds). Based on 1,000 years.

Usage

import { Time } from 'enhanced-ms';

// Calculate 3 days from now
const threeDaysLater = Date.now() + (3 * Time.Day);

// Check if a duration is longer than a week
const duration = 1000000000;
if (duration > Time.Week) {
  console.log('More than a week');
}

// Set a timeout for 5 minutes
setTimeout(() => {
  console.log('5 minutes passed');
}, 5 * Time.Minute);

units

An object containing time unit constants in camelCase. This is functionally identical to Time but uses lowercase naming.
const units = {
  nanosecond: 0.000_001,
  microsecond: 0.001,
  millisecond: 1,
  second: 1_000,
  minute: 60_000,
  hour: 3_600_000,
  day: 86_400_000,
  week: 604_800_000,
  month: 2_628_000_000,
  year: 31_536_000_000,
  decade: 315_360_000_000,
  century: 3_153_600_000_000,
  millennium: 31_536_000_000_000,
} as const;

Properties

nanosecond
number
One nanosecond in milliseconds.
microsecond
number
One microsecond in milliseconds.
millisecond
number
default:1
One millisecond.
second
number
default:1000
One second (1,000 milliseconds).
minute
number
default:60000
One minute (60,000 milliseconds).
hour
number
default:3600000
One hour (3,600,000 milliseconds).
day
number
default:86400000
One day (86,400,000 milliseconds). Based on 24 hours.
week
number
default:604800000
One week (604,800,000 milliseconds). Based on 7 days.
month
number
default:2628000000
One month (2,628,000,000 milliseconds). Based on 28 days as a standard month length.
year
number
default:31536000000
One year (31,536,000,000 milliseconds). Based on 365 days.
decade
number
default:315360000000
One decade (315,360,000,000 milliseconds). Based on 10 years.
century
number
default:3153600000000
One century (3,153,600,000,000 milliseconds). Based on 100 years.
millennium
number
default:31536000000000
One millennium (31,536,000,000,000 milliseconds). Based on 1,000 years.

Usage

import { units } from 'enhanced-ms';

// Calculate expiration time
const expiresAt = Date.now() + (30 * units.day);

// Convert hours to milliseconds
const workDay = 8 * units.hour; // 28,800,000 ms

// Check duration
if (elapsed > units.minute) {
  console.log('Over a minute');
}

Unit type

A union type of all available unit keys.
type Unit = 'nanosecond' | 'microsecond' | 'millisecond' | 'second' | 
            'minute' | 'hour' | 'day' | 'week' | 'month' | 
            'year' | 'decade' | 'century' | 'millennium';
This type is useful when you need to reference unit names programmatically.

Usage

import { units, type Unit } from 'enhanced-ms';

function getDuration(amount: number, unit: Unit): number {
  return amount * units[unit];
}

const twoWeeks = getDuration(2, 'week'); // 1,209,600,000 ms

Notes

  • Month duration: The Month constant uses 28 days as the standard length to avoid ambiguity between different month lengths.
  • Year duration: The Year constant uses 365 days and does not account for leap years.
  • Precision: Sub-millisecond units (Nanosecond and Microsecond) are represented as decimal values since JavaScript’s native time functions work in milliseconds.

Build docs developers (and LLMs) love