Categories
JavaScript Answers

How to convert timestamp to human date in JavaScript?

Spread the love

Sometimes, we want to convert timestamp to human date in JavaScript.

In this article, we’ll look at how to convert timestamp to human date in JavaScript.

How to convert timestamp to human date in JavaScript?

To convert timestamp to human date in JavaScript, we can use the date’s toDateString, toTimeString, or the toLocaleString methods.

For instance, we write

const d = new Date(1382086394000).toDateString();
const t = new Date(1382086394000).toTimeString();
const dt = new Date(1382086394000).toLocaleString();

to create a date object with the Date constructor.

Then we call toDateString to return a human readable date string.

We call toTimeString to return a human readable time string.

And we call toLocaleString to return a human readable localized date time string.

Conclusion

To convert timestamp to human date in JavaScript, we can use the date’s toDateString, toTimeString, or the toLocaleString methods.

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 *