1 date 时间 00:00:00 转成 59:59:99
落数据发现,同事时间格式是
导致结束时间全都是 00:00:00,这不是结束的最大时间格式。
于是重写了 set 方法,把时间换算为最大时间格式
public void setValidEndDate(Date validEndDate) { LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(validEndDate.getTime()), ZoneId.systemDefault()); LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX); this.validEndDate = Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant()); }
测试代码如下:
public static void main(String[] args) { Date validEndDate= new Date(); LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(validEndDate.getTime()), ZoneId.systemDefault()); LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX); Date from = Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant()); System.out.println("from = " + from); }
标签:00,59,validEndDate,ZoneId,日期,LocalDateTime,Date From: https://www.cnblogs.com/zq1003/p/16915276.html