LocalDateTime 处理时间


//如果修改时间在9:20之前 则当天九点半执行mq消费 否则在第二天9点半执行
if (LocalTime.now().compareTo(LocalTime.of(9, 20)) <= 0) {
consumeTime = LocalDate.now().atStartOfDay().plusHours(9).plusMinutes(30);
} else {
consumeTime = LocalDate.now().plusDays(1).atStartOfDay().plusHours(9).plusMinutes(30);
}



Timestamp.valueOf(date).getTime()

Date startBusinessDate = request.getStartBusinessDate();
LocalDate start = startBusinessDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

public static void main(String[] args) {
// 创建两个日期对象
LocalDate date1 = LocalDate.parse("2021-01-01");
LocalDate date2 = LocalDate.parse("2021-03-01");

// 计算日期差异
Period period = getPeriod(date1, date2);

int difference = period.getDays();

System.out.println("日期差异:" + difference + "天");
}

public static Period getPeriod(LocalDate date1, LocalDate date2) {
return Period.between(date1, date2);
}
-----------------------------------
©著作权归作者所有:来自51CTO博客作者mob64ca12e732bb的原创作品,请联系作者获取转载授权,否则将追究法律责任
java怎么计算两个Date相差多少天
https://blog.51cto.com/u_16213393/7072718

posted on 2023-08-17 11:12  潮流教父孙笑川  阅读(50)  评论(0)    收藏  举报

导航