我正在尝试创建一个时间间隔,因为起点是当前时间,最小值和最大值是由用户设置的特殊变量(upperBound)计算的。所以代码如下:
private static int upperBound = 1440;
.....
Calendar calendar = Calendar.getInstance();
System.out.println("Now:\t\t\t" + calendar.getTime());
calendar.set(Calendar.MINUTE, -upperBound);
System.out.println("After the change:\t" + calendar.getTime());
输出是:
Now: Mon Jan 27 14:53:42 EET 2014
After the change: Sun Jan 26 14:00:42 EET 2014
但我预计(更改后):Sun Jan 26 14:53:42 EET 2014
这里出了什么问题?
最佳答案
您应该使用add()
方法,而不是设置
calendar.add(Calendar.MINUTE, -upperBound);
关于java - java日历分钟设置意外值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21381645/