我从 GregorianCalendar 03/25/2018 09:41 中减去 24 小时。
结果 03/24/2018 08:41
。
public class Utiles{
public static void main(String args[]) {
SimpleDateFormat sdt = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
GregorianCalendar gcFinAux = new GregorianCalendar(2018, 2, 25, 9, 41, 0);
System.out.println("1. " + sdt.format(gcFinAux.getTime()));
gcFinAux.add(Calendar.HOUR_OF_DAY, -24);
System.out.println("2. " + sdt.format(gcFinAux.getTime()));
}
}
输出:
1. 25/03/2018 09:41:00
2. 24/03/2018 08:41:00
如果我尝试另一个日期,结果是正确的。
我尝试在 Linux 和 Windows 中使用 JDK1.6.0_45 和 Java 1.8。
有人可以确认您是否得到相同的结果?
谢谢你。