Dates
The built-in Date
class is the standard way to handle dates and times.
When you create a new Date
object, it will initialize to the current timestamp (i.e. now).
Creating a Date
- from timestamp
- month is 0 based (new Date(y, m, d))
Timestamps
-
intro on timestamps
-
UNIX timestamps
Date strings
- allowed formats
Parsing is tricky due to inconsistencies across browsers. Prefer ISO format:
- Avoid non-standard formats like "04/11/2025" which may behave differently in different locales.
Manipulating dates
- retrieving year, month, date, etc
- modifying date
- correctly managing timestamps
Timezones
- all about timezones
- The Date object always stores dates in UTC internally.
- Use
Intl.DateTimeFormat
for time zone-aware formatting
Loading TypeScript...
Comparing dates
- timezones get involved