【发布时间】:2015-10-01 17:52:26
【问题描述】:
我在变量 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)
{
}
【问题讨论】:
-
不知道
x或a的类型会让人很难知道如何显示有关它们差异的信息。似乎它们是整数小时/分钟/秒值的某种包装器,那么为什么不直接提取每个小时/分钟/秒并基于此进行比较呢? -
您甚至可以比较字符串值,例如“14:30:25”。
-
转到here 以获得简短答案