gpt4 book ai didi

javascript - 时刻.js : The result is always "a few seconds ago" in firefox/ie

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:34:42 24 4
gpt4 key购买 nike

我来自 UTC +8 时区,当我尝试将 2014-06-04 12:51:53 +0800/from Rails/timestamp 转换为我的时区时。但它只适用于 chrome,所有其他浏览器都不能应用 UTC 时区。结果总是几秒钟前。这是我的使用方法:

window.updateTimestamps = (elements)->
moment.lang('mn')
moment().tz("Asia/Ulaanbaatar").format()
elements.each( ->
timestamp = moment(new Date($(@).data('datetime')))
$(@).html(timestamp.fromNow())
)


$(document).on('ready', ->

moment.tz.add
zones:
"Asia/Ulaanbaatar": [
"7:7:32 - LMT 1905_7 7:7:32"
"7 - ULAT 1978 7"
"8 Mongol ULA%sT"
]

rules:
Mongol: [
"1983 1984 3 1 7 0 0 1 S"
"1983 1983 9 1 7 0 0 0"
"1985 1998 2 0 8 0 0 1 S"
"1984 1998 8 0 8 0 0 0"
"2001 2001 3 6 8 2 0 1 S"
"2001 2006 8 6 8 2 0 0"
"2002 2006 2 6 8 2 0 1 S"
]
links: {}

这是我要转换的 HTML:

<abbr class="time-ago" data-datetime="2014-06-04 12:51:53 +0800"></abbr>

代码如下:

  timeAgos = $('abbr.time-ago')
window.updateTimestamps(timeAgos)
setInterval(window.updateTimestamps, 60000, timeAgos)

谢谢您的回答。我不知道?请帮助我:)

最佳答案

Javascript 控制台在尝试使用您的日期初始化 moment.js 时显示警告,并建议 read this bug report .您必须将日期转换为 ISO 格式

>>> moment("2014-06-04 12:51:53 +0800").fromNow()
"a few seconds ago"
>>> moment("2014-06-04T12:51:53+0800").fromNow()
"7 days ago"

或者改用格式说明符:

>>> moment("2014-06-04 12:51:53 +0800", "YYYY-MM-DD hh:mm:ss +ZZ").fromNow()
"7 days ago"

关于javascript - 时刻.js : The result is always "a few seconds ago" in firefox/ie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24116613/

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