Sometimes, we want to set just the date, ignoring time with JavaScript Date.
In this article, we’ll look at how to set just the date, ignoring time with JavaScript Date.
How to set just the date, ignoring time with JavaScript Date?
To set just the date, ignoring time with JavaScript Date, we pass in a date string into the Date
constructor.
For instance, we write
const newDate = new Date(oldDate.toDateString());
to get the oldDate
‘s date as a string with toDateString
.
Then we pass that into the Date
constructor to create a new date object with the date.
Conclusion
To set just the date, ignoring time with JavaScript Date, we pass in a date string into the Date
constructor.