时间过去 +当地时间合并

发布于 2024-12-04 07:24:13 字数 971 浏览 8 评论 0原文

我正在尝试将 timeago结合起来datejs (在此帮助下获取timeago的当地时间格式)

我使用以下内容:

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

对于localtime我使用这个:

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

我如何将这两者结合在一起?现在我只能一次使用一个,如下所示:

For Timeago:

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

和 for localtime;

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

会发光的星星闪亮亮i 2024-12-11 07:24:13

除此之外,不要添加任何 javascript 代码或 jquery 代码;

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

然后添加“Z”(或包括 T)。有关更多信息,请访问此链接

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

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

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

无声情话 2024-12-11 07:24:13

我正在尝试做同样的事情 - 这就是我最终想通的。

我的 HTML 有这样的:

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

然后我有这 2 个 javascript 块:

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

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

这是在 HTML 中使用 ASP.NET MVC Razor 语法,但基本上它的作用是获取两种不同格式的日期/时间字符串。所有时间均以 UTC 格式存储。 timeago 插件使用 ISO 8601 格式的字符串来发挥其魔力,而 localtime '插件' 使用 RCF1123 格式。

ISO8601 看起来像这样: yyyy-MM-dd HH:mm:ssZ

RFC1123 看起来像这样: ddd, dd MMM yyyy HH:mm:ss GMT

最终结果是在屏幕上我看到 timeago 的“大约 10 分钟前”,但是当我悬停时,我得到“10/26/2011 08:57:43 PM”。

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文