0Pricing
JavaScript Academy · Lesson

Timestamps and Date Math

Compute differences and offsets between dates.

Timestamps

Internally a date is stored as a timestamp: the number of milliseconds since the Unix epoch, midnight on January 1, 1970, UTC.

const d = new Date("1970-01-01T00:00:00Z")
console.log(d.getTime())

Date.now

Date.now returns the current timestamp in milliseconds without creating a Date object, which is efficient for measuring time.

const t = Date.now()
console.log(typeof t)
console.log(t > 0)

All lessons in this course

  1. Creating and Reading Dates
  2. Timestamps and Date Math
  3. Formatting Dates
  4. Time Zones and UTC
← Back to JavaScript Academy