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中文网其他相关文章!