How to subtract two joda datetimes?
This question already has an answer here:
Period has a constructor that takes two ReadableInstant
instances:
Period diff = new Period(start, end);
( ReadableInstant
is an interface implemented by DateTime
, as well as other classes.)
从你的例子你似乎想在几秒钟内的差异,所以这应该有所帮助:
Seconds diff = Seconds.secondsBetween(start, end);
Does this help? http://joda-time.sourceforge.net/key_period.html It shows the below example
DateTime start = new DateTime(2004, 12, 25, 0, 0, 0, 0);
DateTime end = new DateTime(2006, 1, 1, 0, 0, 0, 0);
// period of 1 year and 7 days
Period period = new Period(start, end);
// calc will equal end
DateTime calc = start.plus(period);
// able to calculate whole days between two dates easily
Days days = Days.daysBetween(start, end);
链接地址: http://www.djcxy.com/p/36648.html
上一篇: 两个日期之间的月差
下一篇: 如何减去两个约会日期?