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)"
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)"
var date = new Date();
console.log(date.toLocaleDateString());
console.log(date.toDateString());
console.log(date.toGMTString());
Choose your method from here: https://www.w3schools.com/js/js_date_methods.asp
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))