JavaScript theorytheory 0/50 · 0%
Fundamentals · easy

19. Dates and timing

Timestamps, seconds vs milliseconds, timers.

`Date.now()` gives milliseconds since the epoch, while Solidity's `block.timestamp` is in seconds — divide or multiply by 1000 at the boundary.

const nowSec = Math.floor(Date.now() / 1000);
const unlock = new Date(unlockSec * 1000).toLocaleString();

`setTimeout` and `setInterval` are best-effort; a busy thread delays them. Clear intervals when a component unmounts.

Check your understanding

  1. 1. What unit does `Date.now()` use?

  2. 2. What unit is `block.timestamp`?

  3. 3. Are timer delays exact?