如何在jquery中获得节省的时间和当前时间的差异? [英] How to get difference of saved time and current time in jquery?

查看:104
本文介绍了如何在jquery中获得节省的时间和当前时间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在javascript或jquery中获取已保存时间和当前时间之间的时差。我节省的时间看起来像 Sun Oct 24 15:55:56 GMT + 05:30 2010

I want to get the time difference between saved time and current time in javascript or jquery. My saved time looks like Sun Oct 24 15:55:56 GMT+05:30 2010.

日期java中的格式代码类似于

The date format code in java looks like

String newDate = "2010/10/24 15:55:56";
DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = format.parse(newDate);

如何将其与当前时间进行比较并获得差异?
jquery或javascript中是否有任何内置函数?

How to compare it with the current time and get the difference? Is there any inbuilt function in jquery or javascript??

任何建议或链接都​​会很感激!!!

Any suggestions or links would be appreciative!!!

提前致谢!

更新

存储日期在DB中作为 varchar 。我正在将它重新转换为String变量,然后将其更改为 java.util.Date object。 java代码看起来像

Date is stored as varchar in the DB. I am retriving it to a String variable and then change it to java.util.Date object. The java code looks like

String newDate = "2010/10/24 15:55:56";
DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = format.parse(newDate);

日期对象已发送至客户端。在那里,我想比较保存的日期和当前日期,并希望显示时间差异像2秒前,2小时前,2天前等...就像在Facebook中一样。我在java脚本中经历了一些日期到时间戳转换教程,现在我可以得到时间戳的差异。现在,我想知道如何将其改为某种格式,如2秒或2天或24小时?或者,我将如何将其更改回日期格式???

This date object was sent to client. There i want to compare the saved date with current date and want to show the time difference like 2 secs ago, 2 hours ago, 2 days ago etc... like exactly in facebook. I have gone through some date to timestamp conversion tutorial in java script and now i can get the difference in timestamp. Now, i want to know how i shall change it to some format like "2 secs or 2 days or 24 hours"??. Or, how i shall change it back to date format???

推荐答案

jQuery不会添加任何用于处理日期的内容。如果 Datejs / en / JavaScript / Reference / global_objects / daterel =nofollow>标准的JavaScript Date API 是不够的。

jQuery doesn't add anything for working with dates. I'd recommend using Datejs in the event that the standard JavaScript Date API isn't sufficient.

也许你可以澄清一下究竟是你的目标输入和输出。 区别是什么意思?有多种方法可以表达时间瞬间(主要是单位和输出字符串格式)之间的差异。

Perhaps you could clarify exactly what input and output you're aiming for. What do you mean by "the difference?" There is more than one way to express the difference between to instants in time (primarily units and output string formatting).

编辑:因为你说你正在使用jQuery,如何使用 CuteTime ? (演示页面

since you said you're working with jQuery, how about using CuteTime? (Demo page)

这篇关于如何在jquery中获得节省的时间和当前时间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆