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.