JS Built-ins
← Date65 / 120
DategetTimeintermediate

getTime() β€” used for date comparison

πŸ“– 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()

Compare two dates by comparing their getTime() values.

Challenge: Verify that the 2024 date has a smaller getTime() than the 2025 date.

πŸ’‘ Hints (1)
  • β€’ Subtracting or comparing getTime() values is the standard way to order or diff two dates