[英]Difference between two dates using the JODA Library
I have two DateTime instances and i would like to find out the exact difference between them. 我有两个DateTime实例,我想找出它们之间的确切区别。 I am using the following
我正在使用以下
DateTime dt = DateUtils.convertFromString(user.getUpdated());
DateTime now = DateTime.now();
Hours hours = Hours.hoursBetween(now, dt);
This off course only gives me the Hours between the two dates. 当然,这给了我两个日期之间的小时数。 I need the complete values like X Day y hours and z minutes.
我需要完整的值,例如X天y小时和z分钟。 How can i do this ?
我怎样才能做到这一点 ?
Period period = new Period(now, dt);
You can provide a PeriodType
which specifies exactly which units you want. 您可以提供一个
PeriodType
来指定所需的确切单位。
(If dt
was in the past, you probably actually want new Period(dt, now)
instead, to give a positive period.) (如果
dt
是过去的,则实际上您实际上可能希望使用new Period(dt, now)
来给出一个正数。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.