我想使用jquery timeago插件 - http://timeago.yarp.com/
我有这样的时间戳1331209044000
,文档说我需要ISO 8601时间戳.
说实话,我从未听说过ISO 8601.
我怎么能转换它?
干杯
我想x seconds ago
基于MySQL时间戳显示.
我发现这个名为timeago的插件
但我找不到让它只显示秒的方法.
61秒或300秒我没问题.有没有办法使用timeago或纯jQuery/JavaScript将输出转换为秒?
谢谢你的帮助 !
示例案例:
$time1 = "2014-02-02 23:54:04"; // plus PHP ways to format it.
//$time2 = NOW() , or date(); whatever.
Run Code Online (Sandbox Code Playgroud)
我只想知道多少秒钟$time1
.
工作代码:
<script type="text/javascript">
$(function(){
var d2 = new Date();
var d1 = new Date("2014-02-02 23:54:04");
$("a#timedif").html("Diff. Seconds : "+((d2-d1)/100).toString());
// note that you may want to round the value
});
</script>
Run Code Online (Sandbox Code Playgroud)
它输出 Diff. Seconds : NaN
我确定这是一个愚蠢的问题,但我真的不知道该怎么做.
我正在使用timeago jquery插件:http://timeago.yarp.com/
它具有多种语言的语言环境支持.
我正在将我的网站从英语翻译成西班牙语,我正在使用PHP来完成这项工作.所以,我也想在两种语言中使用timeago.
我找到了多种语言的字符串:https://gist.github.com/6251
但是我该如何使用它们?
谢谢!
<abbr>
我的HTML中有一个带有"timeago"类的标签.当我在页面加载时设置它的值,然后调用jQuery("abbr.timeago").timeago();
文档就绪功能它的工作原理.
我的问题是,如果我从某些javascript函数动态更改abbr.timeago标题怎么办,如何让timeago插件在更新的abrr.timeago元素上做出魔力呢?
我应该打电话给哪个功能?我应该jQuery("abbr.timeago").timeago();
从文件准备功能中删除还是离开?谢谢
编辑问题:
@squiddy示例工作,只更新一次时间,它只是保持不变.例如,如果我将timeago放到当前时间......那么它只是表示它不会改变?
BOUNTY UPDATE:
请忽略以前的问题.在我的网站上有一个链接,点击它的getJSON函数被调用,它从服务器获取一些信息到表中.
每行代表来自服务器的反馈.这是我的getJSON伪代码:
$.getJSON("feedback/" + feedbackId, function(data) {
var column ... declared variable in which column selector
.... some logic that populates table(irrelevant)
//Store last checked time in title
column.attr("title", iso8601(new Date()));
//invoke timeago on this title
column.html(jQuery.timeago(iso8601(new Date())));
....iso8601 is date format function
});
Run Code Online (Sandbox Code Playgroud)
因此,我从服务器获得的每个反馈都会调用此getJSON(n次).当json完成时,表中的相应列将填充上次更新的时间.
但似乎timeago没有读取更改的标题值,它无法识别更新的DOM.我为服务器的每个反馈设置了一个console.log(element.attr("title")),用于调试目的,看看我是否将title属性设置为当前时间,确实确实如此,但是timeago获取了最初加载的标题值.
我该怎么办我也试过这个版本:
$.getJSON("feedback/" + feedbackId, function(data) {
var column ... declared variable in which column selector
.... some logic that populates table(irrelevant) …
Run Code Online (Sandbox Code Playgroud) 我无法了解页面中的脚本是如何加载的.我有依赖于其他脚本的jQuery插件.我正在使用timeago jQuery插件.我按顺序加载了这个脚本:
<script src="<?php echo base_url().'content/scripts/jqueryEngine/jquery.js' ?>" type="text/javascript"></script> //jquery library
<script src="<?php echo base_url().'content/scripts/timeago.js' ?>" type="text/javascript"></script> //timeago
<script src="<?php echo base_url().'content/scripts/myscript.js' ?>" type="text/javascript"></script> // Custom scripts that contains ajax.
Run Code Online (Sandbox Code Playgroud)
在document ready
我正在初始化timeago.但这不适合我.在控制台中,浏览器显示timeago无法正常运行.我想要的是确保在任何其他脚本运行之前已经加载了timeago.我的脚本还包含多个依赖于timeago的Ajax调用.
我正在努力timeago
与之合作datejs (with help of this to get format for local time)
因为timeago
我使用以下内容:
jQuery(document).ready(function() {
jQuery("abbr.timeago").timeago();
});
Run Code Online (Sandbox Code Playgroud)
对于localtime
我使用这个:
jQuery(document).ready(function() {
$('.UTCTimestamp').localTimeFromUTC('MM/dd/yyyy hh:mm:ss');
});
Run Code Online (Sandbox Code Playgroud)
我如何将这两者结合在一起?现在我只能像这样使用一个:
对于Timeago:
<span class='UTCTimestamp'>2011-09-09 10:10:10</span>
Run Code Online (Sandbox Code Playgroud)
并为当地时间;
<abbr class='timeago' title='2011-09-09 10:10:10'>2011-09-09 10:10:10</abbr>
Run Code Online (Sandbox Code Playgroud) 在我的CakePHP应用程序中,通过使用cake.bat我创建了POT文件并使用PoEdit我创建了PO文件.因此,通过编写__('myword'),我可以成功地在我的应用程序中看到本地化的单词.
但现在我需要本地化"timeAgoInWords".当我运行饼国际化提取物,剧本没有得到_dn()的话在CakeTime http://api20.cakephp.org/view_source/cake-time#line-522
所以我创建了一个dummy.ctp文件和从cake-time文件复制粘贴的内容到虚拟文件.我再次运行蛋糕脚本和POEdit.它创建了如下所示的实例到文件app/Locale/tur/LC_MESSAGES/default.po中
#: View\App\dummy.ctp:30;33
msgid "%d minute"
msgid_plural "%d minutes"
msgstr[0] "%d dakika"
msgstr[1] "%d dakika"
Run Code Online (Sandbox Code Playgroud)
在core.php中,我已经将默认语言设置为土耳其语:
Configure::write('Config.language', 'tur');
Run Code Online (Sandbox Code Playgroud)
但是当我检查我的申请时,timeAgoInWords的结果是英文的.
我怎样才能解决这个问题
localization cakephp internationalization cakephp-2.0 timeago
我有一个值,011-04-29T14:55:33.000Z
这个值被推入jQuery模板.我使用timeago将日期转换为已用时间,但在写入模板后,随着时间的推移,它无法更新.
我将如何实现自动更新的内容?
通过Rails Best Practices运行我完成的Rails Tutorial应用程序让我发出警告,不要使用该time_ago_in_words
方法 "计算服务器端的时间太昂贵",因此他们提供了一些示例代码来更改您的实现以使用timeago jQuery插件.听起来它会做出有趣的改变,所以我试了一下.我使用的原始代码time_ago_in_words
分为两个地方:
应用程序/视图/共享/ _feed_item.html.haml
# ...
%span.timestamp
= t('.time_posted_ago', time: time_ago_in_words(feed_item.created_at) )
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/微柱/ _micropost.html.haml
# ...
%span.timestamp
= t('.time_posted_ago', time: time_ago_in_words(micropost.created_at))
Run Code Online (Sandbox Code Playgroud)
我使用HTML5 time
标记将代码更改为使用timeago,如下所示:
应用程序/视图/共享/ _feed_item.html.haml
# ...
%time.timeago{ datetime: feed_item.created_at.getutc.iso8601 }
= t('.time_posted_ago', time: feed_item.created_at.to_s)
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/微柱/ _micropost.html.haml
# ...
%time.timeago{ datetime: micropost.created_at.getutc.iso8601 }
= t('.time_posted_ago', time: micropost.created_at.to_s)
Run Code Online (Sandbox Code Playgroud)
我想,只留下我将timeago()方法添加到我的coffeescript文件中:
应用程序/资产/ JavaScript的/ application.js.coffee
$(document).ready ->
$("time.timeago").timeago()
Run Code Online (Sandbox Code Playgroud)
这不起作用,所以我尝试将语句移动到microposts.js.coffee和users.js.coffee,有和没有$(document).ready ->
,仍然没有去.然后我想也许默认情况下不包括timeago所需的库jquery-rails
,所以我添加了它们:
应用程序/资产/ JavaScript的/ …
jquery internationalization timeago ruby-on-rails-3 railstutorial.org
我想从 mysql 获取时间戳并将其更改为时间前我的时间戳如下所示:
2021-03-04 06:06:48
Run Code Online (Sandbox Code Playgroud)
在颤振中:
[{id: 1, caption: first post, useruid: b0zbRHZEKMbGSdNoVSjI0gsxXTX2, time: 2021-03-04 06:06:48,}],
Run Code Online (Sandbox Code Playgroud)
错误类型“字符串”不是“日期时间”类型的子类型
在这里,我在此插件的帮助下调用将我的日期和时间更改为 timeago ..
ListView(
children: snapshot.data.map<Widget>((document) {
Provider.of<PostFunctions>(context, listen: false)
.showTimeAgo(document['time']);
return My Other Code...
)
I show like this in My Text
Run Code Online (Sandbox Code Playgroud)
' , ${Provider.of<PostFunctions>(context, listen: false).getImageTimePosted.toString()}'
Run Code Online (Sandbox Code Playgroud)
我在这里更改我的日期和时间
showTimeAgo(dynamic timedata) {
print(timedata);
imageTimePosted = timeago.format(timedata);
print(' my time posted ***** $imageTimePosted');
notifyListeners();
}
Run Code Online (Sandbox Code Playgroud)
timeago ×10
jquery ×8
javascript ×6
ajax ×1
cakephp ×1
cakephp-2.0 ×1
datejs ×1
flutter ×1
locale ×1
localization ×1
plugins ×1
seconds ×1
time ×1