Lesson 30 of 48
63%
Date Objects
A Date object represents a moment in time.
You can read the year, month, day, hour, and more.
Think of a calendar clock living inside your program.
1
Make a Date
2
Read parts
3
Set parts
4
Timestamps
5
Formatting basics
Now
new Date() makes a date for the current moment.
javascript
Specific dates
You can pass a date string or numbers.
Month numbers start at 0 for January.
javascript
Read parts
Getters pull out pieces of the date.
javascript
Set parts
Setters change pieces of the date.
javascript
Timestamps
getTime() gives milliseconds since Jan 1, 1970.
Bigger numbers mean later times.
javascript
Friendly text
toDateString and toISOString help you print dates.
javascript
Tip: Months start at 0. That surprise trips up almost everyone once.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.