我试图获取小时和分钟,然后将分钟四舍五入到最接近的 5。我在这里找到了带有 roundMinutes 函数的 java Calendar 类:enter link description here
我如何在代码中使用它?我尝试创建一个 Calendar 对象、一个 Date 对象,但没有任何东西告诉我要使用这个方法。提供一个例子就太好了!
最佳答案
确保您使用的是 this 日历
。 java的默认日历中没有roundMinutes
。
calendar.roundMinutes(5, Calendar.ROUND_UP) if you want 5:41 to become 5:45
calendar.roundMinutes(5, Calendar.ROUND_DOWN) if you want 5:41 to become 5:40
calendar.roundMinutes(5, Calendar.ROUND_AUTO) if you want 5:41 to become whatever the library thinks is normal.
关于java - 在 Java 中使用 roundMinutes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7040409/