问题
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