gpt4 book ai didi

javascript - 从日期时间戳中删除末尾的 'UTC' 文本

转载 作者:行者123 更新时间:2023-11-30 07:02:36 28 4
gpt4 key购买 nike

我正在使用 date.toGMTString()DateTime 作为 GMT 标准。所以我得到的是 'Fri, 26 Apr 2013 17:08:35 UTC' 这个。我只想在不显示文本 'UTC' 的情况下显示它。请告诉我

最佳答案

使用slice :

date.toGMTString().slice(0, -4)

顺便说一句,你应该注意到 toGMTString is deprecated and the same as toUTCString ,并且该方法确实返回一个依赖于实现的人类可读的 UTC 日期字符串。您不能确定它以 "UTC"(或 "GMT")结尾,因此您可能会使用

date.toUTCString().replace(/\s*(GMT|UTC)$/, "")

关于javascript - 从日期时间戳中删除末尾的 'UTC' 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16287110/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com