获得两个日期之间的Andr​​oid的差异 [英] Getting difference between two dates Android

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

问题描述

是:

2011-03-27T09:39:01.607

和有当前的日期。

我想这两个日期之间差异的形式:

I want to get difference between these two dates in the form of :

2 days ago 
1 minute ago etc..

根据过帐日期。

depending posting date.

现在用这个code张贴日期转换为钢厂秒:

Am using this code to convert posting date to mill seconds:

 public long Date_to_MilliSeconds(int day, int month, int year, int hour, int minute)
{

       Calendar c = Calendar.getInstance();

       c.set(year, month, day, hour, minute, 00);

        return c.getTimeInMillis();

}

这当前日期:长今= System.currentTimeMillis的();

和计算的区别:

 String difference =  (String) DateUtils.getRelativeTimeSpanString(time,now, 0);

但它返回像 1970年5月1日或东西..

如何获得过帐日期和当前日期之间的差异。

推荐答案

你得到1970年是因为它是在毫秒时代日期的理由。为了得到实际相差使用下面的。

The reason you get 1970 is because it is the epoch date in milli seconds. To get the actual difference use the below.

使用 JodaTime

这篇关于获得两个日期之间的Andr​​oid的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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