Sometimes, we want to convert timestamp to human readable format with JavaScript.
In this article, we’ll look at how to convert timestamp to human readable format with JavaScript.
How to convert timestamp to human readable format with JavaScript?
To convert timestamp to human readable format with JavaScript, we can use the date’s setTime
method.
For instance, we write
const newDate = new Date();
newDate.setTime(unixtime * 1000);
const dateString = newDate.toUTCString();
to create a Date
object.
Then we call setTime
with unixtime * 1000
to set the timestamp of newDate
to unixtime * 1000
.
unixtime
is the timestamp of the date in seconds.
then we call toUTCString
to return a human readable date string from newDate
.
Conclusion
To convert timestamp to human readable format with JavaScript, we can use the date’s setTime
method.