Context
Creating a new Date Object
Date objects are native JavaScript objects that we can use in order to work with dates and times. Exactly like the Math object, the Date object has multiple functions that solve problems regarding date issues.
For example when you have a booking flight or hotel website, and you want to force the user to select a specific date from a date field form, or if you want to just depict a countdown from now to a specific date.
There are 4 ways to create a new date object as shown above.
First you need to create a variable and assign a new Date instance there.
1. const currentDate = new Date() // This will create an object with the date and time of creation.
2. const myBirthday = new Date(year, month, day) => example new Date(1988, 02, 23). It stores the date of 23rd of March 1988. More parameters can be put for giving and storing an exact date like hours (0-23), minutes(1-60), seconds etc.
* Yes March is no mistake, the month's counting starts from 0!
3. const myBirthday = new Date('23 Mar 1988") // See more about this option next page!
4. const myBirthday = new Date(17534835345) // The number of milliseconds that have passed since 1.1.1970 // Used for short term date or time differences. Script's execution performance etc.
Find more here: