先看下这个LocalDateTime 的转换
LocalDateTime now = LocalDateTime.now();
System.out.println(now);
LocalDateTime localDateTime = now.plusMinutes(2).plusHours(1).plusSeconds(30);
System.out.println("新时间"+localDateTime);
输出的结果为:
这个方法还是很简单的
然后是date日期的转换:
Date date = new Date();
System.out.println(date);
GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTime(date);
gregorianCalendar.add(Calendar.MINUTE,5);
Date time = gregorianCalendar.getTime();
System.out.println("更改后的时间"+time);
结果为:
成功
补充下LocalDateTime和Date的转换
Date lastBoundDate =
Date.from("localdatetime".atZone(ZoneId.systemDefault()).toInstant());
举个栗子:
Date lastBoundDate =
Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
ok完事