Javascript Date.now to readable format

Viewed 31994
Date.now();

I want to convert the timestamp to readable format

e.g "Fri Nov 17 2017 19:15:15 GMT+0800 (Malay Peninsula Standard Time)"

5 Answers

You could do these following statements

let newDate = new Date();
console.log(`${newDate.toDateString()} ${newDate.toTimeString()}`);

From the answers above, we can also do it in one line. As below,

var dateString = new Date().toDateString();
console.log(dateString, '\n');
var dateString = new Date().toLocaleDateString();
console.log(dateString, '\n');
var dateString = new Date().toGMTString();
console.log(dateString, '\n');

Just new Date();

document.getElementById("demo").innerHTML = Date();
<p id="demo"></p>

You can pass the value you get from Date.now() to new Date() this will give you the time in readable format.

For example:

let timestamp = Date.now();
console.log(new Date(timestamp))
Related