var date = new Date()
输出:"Wed Nov 28 2012 14:55:24 GMT-0500 (Eastern Standard Time)"
想要摆脱UT和时间输出:
"Wed Nov 28 2012"
答案 0 :(得分:5)
您可以使用toDateString()
:
new Date().toDateString(); // "Wed Nov 28 2012"
答案 1 :(得分:3)
使用toDateString
方法代替(隐式)toString
:
> new Date().toDateString()
"Wed, 28 Nov 2012"
然而,it is implementation-dependent,所以如果您确实需要完全符合您的格式,则无法解决问题
var date = new Date();
var day = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][date.getDay()];
var mon = ["Jan", "Feb", "Apr", "Mar", "Mai", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][date.getMonth()];
return day+" "+mon+" "+date.getDate()+" "+date.getFullYear();
或者查看其中一个many Date libraries及其format
方法。