1
var date = new Date()

输出:"Wed Nov 28 2012 14:55:24 GMT-0500 (Eastern Standard Time)"

想摆脱UT和时间输出:

"Wed Nov 28 2012"
4

2 回答 2

5

您可以使用toDateString()

new Date().toDateString();  // "Wed Nov 28 2012"
于 2012-11-28T20:01:25.867 回答
3

使用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方法。

于 2012-11-28T20:02:27.467 回答