JavaScript Event timeStamp Property

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

The timeStamp property is a read-only number: milliseconds from the page (or worker) time origin until the event was created. Learn MDN’s keypress demo, event deltas, reduced precision, and how it differs from Date.now()—with five examples and try-it labs.

01

Kind

Instance property

02

Type

number (ms)

03

From

Time origin

04

Use

Timing / deltas

05

Note

Reduced precision

06

Status

Baseline widely

Introduction

Every event carries a creation time. event.timeStamp tells you how many milliseconds had passed since the document (or worker) started when that event was created.

That makes it great for measuring gaps between clicks, keys, or pointer moves—without depending on the user’s wall clock. Browsers may round the value slightly to reduce fingerprinting.

💡
Beginner tip

Think: timeStamp = “how long after this page started was this event born?” Not “what time is it on the clock?”

Understanding Event.timeStamp

An instance property that returns when the event was created, as a high-resolution timestamp in milliseconds.

  • Unit — milliseconds since the time origin.
  • Window origin — roughly when navigation / document loading began.
  • Worker origin — when the worker was created.
  • DOMHighResTimeStamp — high-res number; precision may be reduced for privacy.
  • Read-only — set by the browser when the event is created.
  • Baseline Widely available on MDN (since July 2015); also in Web Workers.

📝 Syntax

JavaScript
event.timeStamp

Value

A number: milliseconds from the time origin until the event was created (a DOMHighResTimeStamp).

MDN-style read

JavaScript
document.body.addEventListener("keypress", (event) => {
  console.log(event.timeStamp);
});

⚡ Quick Reference

GoalCode / note
Readevent.timeStamp
Show msevent.timeStamp.toFixed(2)
Deltaevent.timeStamp - lastStamp
PrivacyValue may be rounded (e.g. 2 ms in Firefox)
MDN statusBaseline Widely available (since July 2015)

🔍 At a Glance

Four facts to remember about Event.timeStamp.

Type
number

Milliseconds

Zero
origin

Page / worker

Best for
deltas

Between events

Baseline
widely

Since Jul 2015

Examples Gallery

Examples follow MDN Event: timeStamp. Use View Output or Try It Yourself.

📚 Getting Started

Read the stamp on keyboard and mouse events.

Example 1 — Keypress Timestamp (MDN)

Press a key and show event.timeStamp in the page.

JavaScript
function getTime(event) {
  const time = document.getElementById("time");
  time.textContent = event.timeStamp;
}

document.body.addEventListener("keypress", getTime);
Try It Yourself

How It Works

Each keypress event carries its own creation time from the time origin.

Example 2 — Click Timestamp

Log the stamp when a button is clicked.

JavaScript
button.addEventListener("click", (event) => {
  console.log("timeStamp =", event.timeStamp);
});
Try It Yourself

How It Works

The number grows as the page stays open; early clicks show smaller values.

📈 Deltas, Clocks & Throttling

Compare events, contrast with Date.now, and space out actions.

Example 3 — Time Between Two Clicks

Subtract the previous stamp from the current one.

JavaScript
let last = null;

button.addEventListener("click", (event) => {
  if (last !== null) {
    const delta = event.timeStamp - last;
    out.textContent = "Delta: " + delta.toFixed(1) + " ms";
  } else {
    out.textContent = "First click at " + event.timeStamp.toFixed(1);
  }
  last = event.timeStamp;
});
Try It Yourself

How It Works

Deltas stay meaningful even if absolute stamps are rounded for privacy.

Example 4 — timeStamp vs Date.now()

Same click, two different clocks.

JavaScript
button.addEventListener("click", (event) => {
  console.log("event.timeStamp:", event.timeStamp);
  console.log("Date.now():", Date.now());
  // timeStamp ≈ time since page origin
  // Date.now ≈ Unix epoch wall clock
});
Try It Yourself

How It Works

Use timeStamp for in-page event timing; use Date when you need calendar time.

Example 5 — Ignore Clicks Closer Than 500 ms

A tiny throttle using stamp deltas.

JavaScript
let lastAccepted = 0;

button.addEventListener("click", (event) => {
  if (event.timeStamp - lastAccepted < 500) {
    out.textContent = "Ignored (too soon)";
    return;
  }
  lastAccepted = event.timeStamp;
  out.textContent = "Accepted at " + event.timeStamp.toFixed(0);
});
Try It Yourself

How It Works

Event stamps are a natural clock for spacing user input without starting a separate timer.

🛡️ Reduced Time Precision

MDN notes that browsers may round event.timeStamp to help protect against timing attacks and fingerprinting. In Firefox, reduced precision often defaults to about 2 ms; with stronger fingerprinting resistance it can be much coarser (for example 100 ms).

JavaScript
// With reduced precision, values may look "stepped":
// 9934, 10362, 11670, …
// or even multiples of 100 with stronger privacy settings.

For most UI timing (debounce-like gaps of hundreds of milliseconds), reduced precision is fine. Do not rely on microsecond-level differences in web apps.

🚀 Common Use Cases

  • Measuring time between user actions (double-click, combo keys).
  • Simple input throttling without setTimeout.
  • Logging relative event order / latency in demos.
  • Comparing synthetic vs real event timing in tests.
  • Teaching time origin vs wall-clock Date.

🔧 How It Works

1

Time origin starts

Document navigation (or worker creation) begins the clock.

Origin
2

Event is created

Browser records how many ms have passed.

Create
3

Precision may shrink

Engines can round the stamp for privacy.

Privacy
4

You read timeStamp

Handlers use the number alone or as a delta.

📝 Notes

  • MDN: Baseline Widely available (since July 2015) — no Deprecated / Experimental / Non-standard banner.
  • Available in Web Workers.
  • Read-only DOMHighResTimeStamp in milliseconds.
  • Precision may be reduced (fingerprint / timing-attack protection).
  • Related learning: target, isTrusted, Event(), addEventListener(), JavaScript hub.

Universal Browser Support

Event.timeStamp is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. It is also available in Web Workers. Precision may be reduced for privacy.

Baseline · Widely available

Event.timeStamp

Read-only milliseconds since the time origin when the event was created (DOMHighResTimeStamp).

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support; may reduce precision (~2ms default)
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported (legacy behavior / precision differs)
Full support
Event.timeStamp Excellent

Bottom line: Use timeStamp for relative event timing and deltas. Expect rounded precision; prefer Date only for wall-clock needs.

Conclusion

Event.timeStamp is the event’s age in milliseconds since the time origin. Use it to display when an event fired, compute deltas, and space out input—while remembering browsers may round it for privacy.

Continue with type, target, isTrusted, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use deltas between stamps for intervals
  • Prefer it over Date.now() for in-page event timing
  • Expect rounded / stepped values
  • Log stamps when debugging input order
  • Keep throttle gaps well above precision noise

❌ Don’t

  • Assign event.timeStamp yourself
  • Treat it as calendar / wall-clock time
  • Rely on microsecond accuracy in the browser
  • Confuse it with performance.now() “now” samples
  • Build security on ultra-fine timing differences

Key Takeaways

Knowledge Unlocked

Five things to remember about timeStamp

When the event was created, relative to the time origin.

5
Core concepts
🎯02

Origin

page / worker

Clock
🔁03

Deltas

subtract stamps

Pattern
🛡️04

Privacy

may be rounded

Note
🎯05

Baseline

since Jul 2015

Status

❓ Frequently Asked Questions

It is a read-only number on an Event: the time in milliseconds when the event was created, measured from the beginning of the time origin.
No. MDN marks Event.timeStamp as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is also available in Web Workers.
In a Window, it is typically when navigation to the document started (for example when the user followed a link or a script started loading the document). In a worker, it is when the worker was created.
It is a DOMHighResTimeStamp. Spec-wise it can be accurate to about 5 microseconds, but browsers often reduce precision to help prevent fingerprinting and timing attacks.
Store the first event.timeStamp, then subtract it from a later event.timeStamp. That delta is in milliseconds (subject to reduced precision).
No. Date.now() is wall-clock time since the Unix epoch. event.timeStamp is relative to the document/worker time origin—better for comparing event timing within a page.
Did you know?

performance.now() and event.timeStamp share the same general idea of a high-resolution clock from the time origin, but they answer different questions: now in script vs when this event object was created.

Next: type

Read the event name string and share handlers across event kinds.

type →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful