计算两次的Andr​​oid之间的时间 [英] Calculate time between two times Android

查看:101
本文介绍了计算两次的Andr​​oid之间的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个时间

currentTime = DateFormat.getTimeInstance().format(new Date());

和我要计算多少时间已经过去,因为currentTime的。
任何想法?

and i want to calculate how much time has past since currentTime. any ideas?

推荐答案

您currentTime的如上将是一个字符串,那么难的工作。

Your currentTime as above will be a String, so difficult to work with.

如果您使用日​​期对象,而不是:

If you use a Date object instead:

Date interestingDate = new Date();

,那么你可以通过执行发现在实际的当前日期和interestingDate毫秒之间的不同:

then you can find the different in milliseconds between the actual current date and interestingDate by doing:

(new Date()).getTime() - interestingDate.getTime()

还检查了时间类,你也可以使用Date类的。

Also check out the Time class which you could use instead of the Date class.

这篇关于计算两次的Andr​​oid之间的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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