Joda-Time中兩個日期之間的天數 - Number of days between two dates in Joda-Time

問題:

How do I find the difference in Days between two Joda-Time DateTime instances? 如何找到兩個Joda-Time DateTime實例之間的天數差異? With 'difference in days' I mean if start is on Monday and end is on Tuesday I expect a return value of 1 regardless of the hour/minute/seconds of the start and end dates. “天數差異”是指如果開始時間是星期一而結束時間是星期二,我預計返回值爲1,無論開始日期和結束日期的小時/分鐘/秒。

Days.daysBetween(start, end).getDays() gives me 0 if start is in the evening and end in the morning. Days.daysBetween(start, end).getDays()如果開始是在晚上並在早上結束,則給出0。

I'm also having the same issue with other date fields so I was hoping there would be a generic way to 'ignore' the fields of lesser significance. 我也和其他日期字段有同樣的問題所以我希望有一種通用的方法來“忽略”不太重要的字段。

In other words, the months between Feb and 4 March would also be 1, as would the hours between 14:45 and 15:12 be. 換句話說,2月到3月4日之間的月份也是1,而14:45到15:12之間的時間也是1。 However the hour difference between 14:01 and 14:55 would be 0. 但是,14:01和14:55之間的小時差異爲0。


解決方案:

參考一: https://stackoom.com/question/FxIz
參考二: Number of days between two dates in Joda-Time
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章