JS Built-ins
← Date100 / 120
DatetoISOStringbeginner

toISOString() β€” includes year 2024

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

Use toISOString() to serialize a Date as a UTC ISO 8601 string in the format YYYY-MM-DDTHH:mm:ss.sssZ.

Date.prototype.toISOString()

The year appears at the start of the ISO string.

Challenge: Verify that new Date('2024-01-15T00:00:00.000Z').toISOString() includes '2024'.

πŸ’‘ Hints (1)
  • β€’ toISOString() is lossless β€” the round-trip through a UTC string preserves all information