gpt4 book ai didi

java - java中如何求两次的差值?

转载 作者:行者123 更新时间:2023-12-01 11:06:29 24 4
gpt4 key购买 nike

我在变量 a 中使用 hh:mm:ss 格式设置了时间,并在变量 x 中设置了当前时间,格式相同。在 if 语句中,如果当前时间小于设置时间,我希望它打印出达到设置值所需的 hh:mm:ss 时间。谢谢

a.setHours(7);
a.setMinutes(45);
a.setSeconds(00);
currenttime.format(x);
if (x.compareTo(a)<0); //x is current time (hh:mm:ss)
{
//how do you outprint difference between x and a
System.out.print("You have event in: " x);
}
if (x.compareTo(a)>0 && x.compareTo(a1)<0)
{
}

最佳答案

也许您应该看看java.time.Duration,如本文 how-to-find-difference-between-two-joda-time-datetimes-in-minutes 中所述。

或者您也可以使用joda-time相反,请按照此处介绍的详细信息 number-of-days-between-two-dates-in-joda-time

Using the Days class with the withTimeAtStartOfDay method should work

...或者在这篇文章中how-to-calculate-difference-between-two-dates-in-years-etc-with-joda-time

...除非您已经在使用 Java 8,因为

Joda-Time is the de facto standard date and time library for Java. From Java SE 8 onwards, users are asked to migrate to java.time (JSR-310)

关于java - java中如何求两次的差值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32893818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com