Timeago + Localtime combined

醉酒当歌 提交于 2019-12-23 10:00:09

问题


I'm trying to combine timeago with datejs (with help of this to get format for local time)

for timeago I use the following:

jQuery(document).ready(function() {
  jQuery("abbr.timeago").timeago();
});

For the localtime i use this:

jQuery(document).ready(function() {
    $('.UTCTimestamp').localTimeFromUTC('MM/dd/yyyy hh:mm:ss');
});

How do I combine those two together? Right now I'm only able to use one at the time like this:

For Timeago:

<span class='UTCTimestamp'>2011-09-09 10:10:10</span>

and for localtime;

<abbr class='timeago' title='2011-09-09 10:10:10'>2011-09-09 10:10:10</abbr>

回答1:


don't add any javascript code or jquery code except this;

$('.timeago').timeago();

and then add 'Z' (or including T). for more information go to this link

<abbr class='timeago' title='2011-09-09 10:10:10Z'></abbr>

http://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations




回答2:


I am trying to do the same thing - here is what I finally figured out.

My HTML has this:

<abbr class="timeago localtime" title="@Model.GetLastUpdatedDateTimeISO8601(category, report)">@Model.GetLastUpdatedDateTimeRFC1123(category,report)</abbr><br />

I then have these 2 chunks of javascript:

 $('.localtime').localTimeFromUTC('MM/dd/yyyy hh:mm:ss a');

 $('.timeago').timeago();

This is using ASP.NET MVC Razor syntax in the HTML, but basically what that does is get the date/time strings in two different formats. All times are stored in UTC. The timeago plugin uses the ISO 8601 formatted string to do its magic, and the localtime 'plugin' uses the RCF1123 format.

ISO8601 looks like this: yyyy-MM-dd HH:mm:ssZ

RFC1123 looks like this: ddd, dd MMM yyyy HH:mm:ss GMT

The final result is that on-screen I see timeago's "about 10 minutes ago", but when I hover I get "10/26/2011 08:57:43 PM".



来源:https://stackoverflow.com/questions/7407592/timeago-localtime-combined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!