Javascript Date.now 为可读格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47349417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript Date.now to readable format
提问by Rex Adrivan
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)"
例如“2017 年 11 月 17 日星期五 19:15:15 GMT+0800(马来半岛标准时间)”
回答by jmtalarn
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
从这里选择你的方法:https: //www.w3schools.com/js/js_date_methods.asp
回答by Christophe Coquelet
You could do these following statements
你可以做以下这些陈述
let newDate = new Date(Date.now());
console.log(`${newDate.toDateString()} ${newDate.toTimeString()}`);
回答by Melchia
Just new Date();
只是新的日期();
document.getElementById("demo").innerHTML = Date();
<p id="demo"></p>

