0

我的 Twitter 时间必须转换为 timeago 时间。它在 Chrome 中完美运行,但在 Firefox 中,只有三个工作中的第一个,其他两个返回我 NaN。

这是我使用的插件。http://timeago.yarp.com/

什么会导致这种情况?

// console return

> Fri Jul 11 16:43:21 +0000 2014
> about a month ago
> Tue Jun 17 17:33:19 +0000 2014
> NaN years ago
> Tue Jun 17 16:13:03 +0000 2014
> NaN years ago

我将它与车把一起使用。我创建了一个处理程序来完成工作。

if($.timeago){
    jQuery.timeago.settings.strings = {
       // environ ~= about, it's optional
       prefixAgo: "il y a",
       prefixFromNow: "d'ici",
       seconds: "moins d'une minute",
       minute: "environ une minute",
       minutes: "environ %d minutes",
       hour: "environ une heure",
       hours: "environ %d heures",
       day: "environ un jour",
       days: "environ %d jours",
       month: "environ un mois",
       months: "environ %d mois",
       year: "un an",
       years: "%d ans"
    };
    Handlebars.registerHelper('timeAgo', function(date) {
        console.log(date);
        console.log(jQuery.timeago(date));
        return jQuery.timeago(date);
    });
}

我在车把循环中使用它。

{{#each tweets}}
<li class="col-md-4"><div class="tweet"><a href="https://twitter.com/{{user.screen_name}}" class="tweetImg"><img alt="{{user.screen_name}}" src="{{user.profile_image_url}}" /></a><article>{{tweet text}}<span class="date">{{timeAgo created_at}}</span></article></div></li>
{{/each}}

这是我的对象数组

在此处输入图像描述

4

1 回答 1

1

我找到了答案。

这是 timeAgo 插件的解析错误。

s = s.replace(/T/," ").replace(/Z/," UTC");

此行删除了星期二和星期四的“T”并给出了日期错误。

s = s.replace(/Z/," UTC");

我用上面的这一行替换了它(根据我的需要,它是正确的)。

于 2014-08-15T19:04:30.307 回答