Sometimes, we want to convert the Date.now
value to a readable format with JavaScript.
In this article, we’ll look at how to convert the Date.now
value to a readable format with JavaScript.
How to convert the Date.now value to a readable format with JavaScript?
To convert the Date.now
value to a readable format with JavaScript, we can use the toLocaleString
method.
For instance, we write:
const date = new Date(Date.now());
console.log(date.toLocaleDateString());
to call Date.now
to return a timestamp.
Then we create a Date
instance from the timestamp and assign it to date
.
Finally, we call date.toLocaleString
to return a localized date string.
Conclusion
To convert the Date.now
value to a readable format with JavaScript, we can use the toLocaleString
method.