Categories
JavaScript Answers

How to return human readable string without time from a JavaScript date object?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *