JS Built-ins
← Date61 / 120
DategetTimebeginner

getTime() β€” epoch returns 0

πŸ“– Usage Example
const d = new Date('2024-01-15T00:00:00.000Z')
d.getTime()  // β†’ 1705276800000
new Date(0).getTime()  // β†’ 0

Use getTime() to get the number of milliseconds elapsed since the Unix epoch (Jan 1, 1970 UTC).

Date.prototype.getTime()

Returns milliseconds since the Unix epoch (Jan 1, 1970 00:00:00 UTC). For the epoch itself this is 0.

Challenge: Verify that new Date(0).getTime() returns 0.

πŸ’‘ Hints (1)
  • β€’ new Date(0) creates the Unix epoch; its getTime() is exactly 0