var date = new Date()
输出:"Wed Nov 28 2012 14:55:24 GMT-0500 (Eastern Standard Time)"
想摆脱UT和时间输出:
"Wed Nov 28 2012"
var date = new Date()
输出:"Wed Nov 28 2012 14:55:24 GMT-0500 (Eastern Standard Time)"
想摆脱UT和时间输出:
"Wed Nov 28 2012"
您可以使用toDateString()
:
new Date().toDateString(); // "Wed Nov 28 2012"
使用toDateString
方法代替 (implicit) toString
:
> new Date().toDateString()
"Wed, 28 Nov 2012"
但是,它是依赖于实现的,所以如果你真的需要你的格式,你就不会绕过
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();
或查看众多 Date 库之一及其format
方法。