时间过去 +日期JS = NaN
我正在尝试使用 timeago
(来源),与 datejs
,它不起作用。这是我希望能够工作的一些示例代码(假设已加载 timeago
和 datejs
):
>>> d = new Date()
Mon Jun 21 2010 13:24:37 GMT-0400 (EST) { _orient=1, more...}
>>> d.toISOString() // datejs.toISOString
"2010-06-21T17:24:37.501Z" // this is a valid ISO8601 string, I believe
>>> $.timeago(d.toISOString()) // this should work
"NaN years ago"
我非常感谢任何关于为什么这可能会失败的输入,以及如何解决或规避这一问题。
谢谢。
布莱恩
I'm trying to use timeago
(source), with datejs
, and it's not working. Here's some sample code I'd expect to work (given that timeago
and datejs
are loaded):
>>> d = new Date()
Mon Jun 21 2010 13:24:37 GMT-0400 (EST) { _orient=1, more...}
>>> d.toISOString() // datejs.toISOString
"2010-06-21T17:24:37.501Z" // this is a valid ISO8601 string, I believe
>>> $.timeago(d.toISOString()) // this should work
"NaN years ago"
I'd be much obliged for any input as to why this may be failing, and how one could go about fixing or circumventing this problem.
Thank you.
Brian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(我是Timeago的作者)
问题在于datejs输出的ISO8601时间戳包含一个毫秒值。 Timeago 目前不支持这种详细的 ISO8601 时间戳;它仅支持 ISO8601 规范的一个子集。
这不是我第一次听说这个问题;是时候推出一个补丁来处理 millis 了。我创建了一个问题来跟踪此问题。请留意即将推出的 Timeago 版本。可能是 v0.9。
更新: 现在有一个新版本的 Timeago (v0.9),支持时间戳中的毫秒。 在此处下载。这是相关提交。
(I'm the author of Timeago)
The problem lies in the fact that the ISO8601 timestamp output by datejs includes a milliseconds value. Timeago currently doesn't support this detailed of an ISO8601 timestamp; it only supports a subset of the ISO8601 spec.
This isn't the first time I've heard about this problem; it's time there's a patch to handle the millis. I created an issue to track this. Look out for an upcoming version of Timeago. Likely v0.9.
Update: There's now a new version of Timeago (v0.9) that supports milliseconds in the timestamps. Download it here. Here's the relevant commit.
我对
jquery.timeago.js
进行了以下修补程序,解决了该问题:I made the following patch to
jquery.timeago.js
, which resolves the problem: