Modern JavaScript/TypeScript Clock Library -- No jQuery Required
Synchronizes with your system time and updates every second.
System clock with centisecond precision (10ms updates).
Uses requestAnimationFrame for smoother updates. Falls back to setTimeout when page is hidden!
Counts down from 5 minutes with a callback when done. Uses the new reset() method!
Starts at 10:30:45 and counts up. Use setTime() to change the time!
30-second countdown with centisecond precision. Uses reset() method!
Feature request fulfilled! Shows time in 12-hour format with AM/PM indicator.
Show times from different timezones using IANA names. Automatically handles daylight saving time!
All buttons work independently! (This was the bug in the old version)
Counts up from 00:00:00. Uses the new stopwatch option!
Record split times (cumulative) during your run!
Lap times with delta vs best! Uses lapMode: 'both'
| Lap | Lap Time | Split Time | Delta |
|---|
useAnimationFrame option - uses rAF when visible, falls back to setTimeout when hiddenselenium/standalone-all-browsers on port 4444, running headless Chrome/Firefox/Edge end-to-end scenarios (including extended background-tab behavior)JavaScript:
import { createClock } from 'new-js-clock';
// System clock
const clock = createClock(document.getElementById('clock'));
// Countdown timer
const countdown = createClock(
document.getElementById('timer'),
'00:05:00',
{
countdown: true,
callback: () => alert('Time is up!')
}
);
// With centiseconds
const precision = createClock(
document.getElementById('precision'),
undefined,
{ showCenti: true }
);
TypeScript:
import { createClock, ClockInstance, ClockOptions } from 'new-js-clock';
// System clock with types
const clock: ClockInstance = createClock(
document.getElementById('clock')!
);
// Countdown timer with typed options
const countdownOptions: ClockOptions = {
countdown: true,
callback: () => alert('Time is up!')
};
const countdown: ClockInstance = createClock(
document.getElementById('timer')!,
'00:05:00',
countdownOptions
);
// High precision clock
const precision: ClockInstance = createClock(
document.getElementById('precision')!,
undefined,
{ showCenti: true }
);
// Type-safe method calls
const time: string = clock.getTime();
const isRunning: boolean = clock.isRunning();