如何在JavaScript中获取当前日期?
当前回答
new Date().toDateString();
结果:
“2016年2月3日星期三”
其他回答
像这样漂亮地打印日期。
2015年6月1日上午11:36:48
https://gist.github.com/Gerst20051/7d72693f722bbb0f6b58
new Date().toDateString();
结果:
“2016年2月3日星期三”
这可能会帮助你
var date = new Date();
console.log(date.getDate()+'/'+(date.getMonth()+1)+'/'+date.getFullYear());
这将以dd/MM/yyyy格式打印当前日期
new Date().toISOString().slice(0,10);
也会起作用
var utc=new Date().toJSON().slice(0,10).replace(/-/g,'/');文档.写入(utc);
如果要重用utc变量,例如new Date(utc),请使用替换选项,因为Firefox和Safari无法识别带破折号的日期。