MoreLesson 285Free preview
Get Current Date
This lesson is part of How To · All levels
Summary
JavaScript provides the Date object to take the current date and time. The month's value starts from 0 for January, so it often needs to be added one or mapped to the month's name. For a neat look, you can arrange the string yourself or use Intl.DateTimeFormat to format it to suit the locale.
Key points
- New Date() without argument generates the date and time now
- GetFullYear(), getMonth(), and getDate() take years, months, and dates
- Returns 0-11, so January is 0.
- Returns the index of days in a week, Sunday is 0.
- Intl.DateTimeFormat helps to format dates according to locale
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.