【发布时间】:2013-04-29 19:55:09
【问题描述】:
我使用date.toGMTString() 获取DateTime 作为GMT 标准。所以我得到的是'Fri, 26 Apr 2013 17:08:35 UTC'这个。我只想在没有文本'UTC' 的情况下显示它。请告诉我
【问题讨论】:
-
date.toGMTString().substr(0, 25)
标签: javascript datetime utc
我使用date.toGMTString() 获取DateTime 作为GMT 标准。所以我得到的是'Fri, 26 Apr 2013 17:08:35 UTC'这个。我只想在没有文本'UTC' 的情况下显示它。请告诉我
【问题讨论】:
date.toGMTString().substr(0, 25)
标签: javascript datetime utc
使用slice:
date.toGMTString().slice(0, -4)
顺便说一句,您应该注意到toGMTString is deprecated and the same as toUTCString,并且该方法确实返回了一个依赖于实现人类可读的UTC日期字符串。你不能确定它是否以" UTC"(或" GMT")结尾,所以你宁愿使用
date.toUTCString().replace(/\s*(GMT|UTC)$/, "")
【讨论】:
slice 变得依赖?或者有没有可能它不会以任何额外的东西结束?
toGMTString() 是 deprecated...改用toUTCString()...
date.toUTCString().slice(0, -4)
【讨论】:
var d= new Date();
d=d.toLocaleString();
//Converts a Date object to a string, using locale conventions
//hence the UTC or GMT+.. is removed
【讨论】: