We can create Date object using the new Date() constructor. We can use this constructor by passing different values to it to generate the date object. Lets see all four of them one by one.
1. new Date() – it creates the new date object with current date and time.
let today_date = new Date(); //sets the current date and time
let date = new Date(1598932800000); //sets as Tue Sep 01 2020 00:00:00 GMT-0400
let date = new Date(2017,05,09,09,55,30); //Fri Jun 09 2017 09:55:30 GMT-0400 (Eastern Daylight Time) let date1 = new Date(2017,10); //Wed Nov 01 2017 00:00:00 GMT-0400 (Eastern Daylight Time) let date2 = new Date(2017,07,3); //Thu Aug 03 2017 00:00:00 GMT-0400 (Eastern Daylight Time)
4. new Date(dateString) – it creates the new date object with provided date and time as string
let date = new Date("November 13, 2018 13:13:00"); //Tue Nov 13 2018 13:13:00 GMT-0500 (Eastern Standard Time)
I hope this post was helpful to you. If you like my post, follow me @twitter/andramazo.