Categories
JavaScript Answers

How to convert timestamp to human readable format with JavaScript?

Spread the love

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.

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 *