用途:TemporalAccessor 工具类封装
使用场景
TemporalAccessor 的实现类包含
Instant
LocalDateTime
ZonedDateTime
OffsetDateTime
LocalDate
LocalTime
OffsetTime
项目引用
此博文的依据:hutool-5.6.5版本源码
String dateStr = "2021-05-22T14:05:20"; LocalDateTime localDateTime = LocalDateTime.parse(dateStr); Assert.assertEquals(dateStr,TemporalAccessorUtil.format(localDateTime,DateTimeFormatter.ISO_LOCAL_DATE_TIME));
String dateStr = "2021-05-22"; //TemporalAccessor 的实现类包含Instant LocalDateTime ZonedDateTime OffsetDateTime LocalDate LocalTime OffsetTime LocalDate localDate = LocalDate.parse(dateStr); //Date对象 long time = TemporalAccessorUtil.toEpochMilli(localDate); Assert.assertEquals(DateUtil.parse(dateStr).getTime(), time);