要获取当前时间的整点,可以使用Java中的Calendar类或LocalDateTime类来实现。以下是两种方法:
使用Calendar类:// 创建一个Calendar实例Calendar calendar = Calendar.getInstance();// 将分钟和秒数设置为0calendar.set(Calendar.MINUTE, 0);calendar.set(Calendar.SECOND, 0);// 获取当前时间的整点时间Date currentTime = calendar.getTime();使用LocalDateTime类:// 获取当前时间LocalDateTime now = LocalDateTime.now();// 获取整点时间LocalDateTime hourStart = now.withMinute(0).withSecond(0).withNano(0);// 将LocalDateTime转换为DateDate currentTime = Date.from(hourStart.atZone(ZoneId.systemDefault()).toInstant());以上两种方法都可以获取当前时间的整点时间,可以根据实际需求选择使用哪种方法。


