Joda-Time DateTimes:計算以分鐘為單位的時差
如何確定兩個Joda-Time DateTimes 之間的時差幾分鐘內?方法如下:
要計算兩個DateTimes 之間的時間差(以分鐘為單位),請使用以下方法:
<code class="java">public class DateTimeDifferenceExample { public static void main(String[] args) { // Create two DateTimes DateTime datetime1 = new DateTime(); DateTime datetime2 = datetime1.plusMinutes(30); // Calculate the difference using Duration Duration duration = new Duration(datetime1, datetime2); long minutesDifference = duration.getStandardMinutes(); // Alternatively, you can use Minutes.minutesBetween() method: long minutesDifference2 = Minutes.minutesBetween(datetime1, datetime2).getMinutes(); // Output the difference System.out.println("Minutes difference: " + minutesDifference); System.out.println("Minutes difference using Minutes.minutesBetween(): " + minutesDifference2); } }</code>
輸出:
Minutes difference: 30 Minutes difference using Minutes.minutesBetween(): 30
以上是如何計算兩個 Joda-Time DateTime 之間的時間差(以分鐘為單位)?的詳細內容。更多資訊請關注PHP中文網其他相關文章!