Basic Timer
00:00
Stopped
Timer with Callbacks
00:00
Countdown to Date
00:00:00
Auto-start Timer
00:00
Documentation
// Basic usage
const timer = new Timer({
duration: 120,
onTick: (t) => console.log("Time left:", t),
onComplete: () => alert("Done!")
});
timer.start();
// Pause and resume
timer.pause();
timer.resume();
// Stop and reset
timer.stop();
timer.reset();
// Format time
timer.format(); // "01:25"
timer.format("hh:mm:ss"); // "00:01:25"
// Countdown to date
const dateTimer = Timer.toDate("2025-01-01T00:00:00Z", {
onTick: (t) => console.log(t),
onComplete: () => console.log("Happy New Year!")
});
// Auto-start
const autoTimer = new Timer({
duration: 30,
autoStart: true
});
// Millisecond precision
const msTimer = new Timer({
duration: 5000, // 5 seconds in milliseconds
precision: "millisecond",
onTick: (t) => console.log(t)
});
// Static start method
const quickTimer = Timer.start(60); // Creates and starts a 60-second timer