使用joda时间的两个日期之间的差异? [英] difference in seconds between two dates using joda time?
问题描述
假设有两个日期A(开始时间)& B(结束时间)。 A& B可以是同一天甚至不同日子的时间。我的任务是以秒为单位显示差异。我正在使用的日期格式是
Suppose there are two dates A(start time) & B(end time). A & B could be the time on the same day or even different day. My task is to show difference in seconds. Date format which i am using is
Date Format :: "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
例如
start date :: "2011-11-16T14:09:23.000+00:00"
end date :: "2011-11-17T05:09:23.000+00:00"
感谢帮助。
推荐答案
使用 Seconds
类:
DateTime now = DateTime.now();
DateTime dateTime = now.plusMinutes(10);
Seconds seconds = Seconds.secondsBetween(now, dateTime);
System.out.println(seconds.getSeconds());
这段代码打印出来600.我认为这就是你需要的。
This piece of code prints out 600. I think this is what you need.
作为进一步的建议,请浏览 joda-time
的文档。它非常好,大多数东西都很容易被发现。
As further advice, explore the documentation of joda-time
. It's pretty good, and most things are very easy to discover.
如果您在解析日期时需要一些帮助(实际上是在文档中),请查看相关问题,如下所示:
In case you need some help with the parsing of dates (It's in the docs, really), check out the related questions, like this:
这篇关于使用joda时间的两个日期之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!