Sometimes, we want to return human readable string without time from a JavaScript date object.
In this article, we’ll look at how to return human readable string without time from a JavaScript date object.
How to return human readable string without time from a JavaScript date object?
To return human readable string without time from a JavaScript date object, we can call the toDateString
method on the date object.
For instance, we write:
const dateData = "07-21-2022";
const dateObject = new Date(Date.parse(dateData));
const dateReadable = dateObject.toDateString();
console.log(dateReadable)
We write:
const dateObject = new Date(Date.parse(dateData));
to create a new date object.
Then we call toDateString
to return the human readable string version of the dateObject
.
Conclusion
To return human readable string without time from a JavaScript date object, we can call the toDateString
method on the date object.