JavaScript Dates
JavaScript's built-in Date object represents a moment in time as milliseconds since the Unix epoch (January 1, 1970 UTC). It handles dates, times, and timezones.
JavaScript's built-in Date object represents a moment in time as milliseconds since the Unix epoch (January 1, 1970 UTC). It handles dates, times, and timezones.
const now = new Date();
console.log(now.toString()); // Human-readable local time
console.log(now.toISOString()); // "2024-06-15T10:30:00.000Z"
console.log(now.getTime()); // milliseconds since epoch
const epoch = new Date(0);
console.log(epoch.toISOString()); // "1970-01-01T00:00:00.000Z"
The built-in Date object has quirks (month is 0-indexed, parsing is inconsistent) — consider using Temporal API or a library for complex use cases.
More in JavaScript