我使用date.toGMTString()
将DateTime
作为GMT标准。所以我得到的是'Fri, 26 Apr 2013 17:08:35 UTC'
这个。我只想在没有文字'UTC'
的情况下显示它。请让我知道
答案 0 :(得分:7)
使用slice
:
date.toGMTString().slice(0, -4)
顺便说一句,你应该注意到toGMTString
is deprecated and the same as toUTCString
,并且该方法确实返回了一个依赖于实现的人类可读的UTC日期字符串。您无法确定它是否以" UTC"
(或" GMT"
)结尾,因此您可能会使用
date.toUTCString().replace(/\s*(GMT|UTC)$/, "")
答案 1 :(得分:2)
toGMTString()
deprecated ...请改用toUTCString()
...
date.toUTCString().slice(0, -4)
答案 2 :(得分:2)
var d= new Date();
d=d.toLocaleString();
//Converts a Date object to a string, using locale conventions
//hence the UTC or GMT+.. is removed
答案 3 :(得分:1)