Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我开始玩JodaTime,但没有找到一种方便的方法来计算 2 个DateTime对象之间的天数差异。我想出的最好的如下:
DateTime
//given DateTime dt1 and dt2 long distanceInMillis = dt2.getMillis()-dt1.getMillis(); int distanceInDays = (int)(distanceInMillis / 24*60*60*1000L);
我将不胜感激您对如何做得更好的建议。
不!使用毫秒计算天数的许多夏令时错误 :)
乔达提供
Days d = Days.daysBetween(dt1, dt2); int days = d.getDays();