native-dates

Examples / Durations

Countdown to a launch

Count down live to Friday at 5:00 PM and display the remaining duration in full, narrow, and digital styles.

Try this

  1. Watch each second tick as now().until(launch) recomputes the remaining span.
  2. Change 'friday' to 'monday' in app.js to move the target launch day.
  3. Pick Asia/Tokyo in the preview bar, where Friday at 5:00 PM arrives hours sooner.
import { now, today } from 'native-dates';

const launch = today().next('friday').at('5pm');

document.querySelector('#launch').textContent = launch.format('full');

function tick() {
  const left = now().until(launch).round('second');
  document.querySelector('#long').textContent = left.format();
  document.querySelector('#narrow').textContent = left.format('narrow');
  document.querySelector('#digital').textContent = left.format('digital');
}

setInterval(tick, 1000);
tick();

Starting…

How it works

The target moment comes from today().next('friday').at('5pm'). That steps forward to the upcoming Friday and sets the local clock to five in the afternoon.

Every second, now().until(launch) measures the remaining span in days, hours, minutes, and seconds. Calling round('second') trims milliseconds so the live readout steps cleanly.

Finally, format() renders that same duration in full words alongside its narrow and digital timer styles, without dividing by milliseconds.