Tag: seconds

如何使用jQuery以秒为单位获得两个时间戳之间的时差?

我想基于MySQL时间戳显示x seconds ago 。 我找到了名为timeago的插件 但我找不到让它只显示秒的方法。 61秒或300秒我没问题。 有没有办法使用timeago或纯jQuery / JavaScript将输出转换为秒? 谢谢你的帮助 ! 编辑: 示例案例: $time1 = “2014-02-02 23:54:04”; // plus PHP ways to format it. //$time2 = NOW() , or date(); whatever. 我只想得到自$time1以来的秒数。 编辑2: 工作代码: $(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 […]