我date.toGMTString()
用来获取DateTime
格林威治标准时间标准。所以我得到的是'Fri, 26 Apr 2013 17:08:35 UTC'
这个。我只想在没有文本的情况下显示它'UTC'
。请告诉我
问问题
6882 次
4 回答
7
使用slice
:
date.toGMTString().slice(0, -4)
顺便说一句,您应该注意到它toGMTString
已被弃用并且与 相同toUTCString
,并且该方法确实返回了一个依赖于实现的人类可读的 UTC 日期字符串。您不能确定它是否以" UTC"
(or " GMT"
) 结尾,因此您宁愿使用
date.toUTCString().replace(/\s*(GMT|UTC)$/, "")
于 2013-04-29T20:01:20.920 回答
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
于 2014-01-29T17:19:20.400 回答
2
toGMTString()
已弃用...toUTCString()
改用...
date.toUTCString().slice(0, -4)
于 2013-04-29T20:03:36.720 回答