// timestamp可以通过long l = System.currentTimeMillis();这种方式去获取到,当然也可以通过其他的方式获取publicstaticLocalDateTimegetDateTimeOfTimestamp(long timestamp){Instant instant =Instant.ofEpochMilli(timestamp);ZoneId zone =ZoneId.systemDefault();returnLocalDateTime.ofInstant(instant, zone);}
3.将LocalDateTime转为long类型的timestamp
publicstaticlonggetTimestampOfDateTime(LocalDateTime localDateTime){ZoneId zone =ZoneId.systemDefault();Instant instant = localDateTime.atZone(zone).toInstant();return instant.toEpochMilli();}
4.将某时间字符串转为自定义时间格式的LocalDateTime
// time 是需要被格式化的时间字符串// format 是自己定义的时间格式publicstaticLocalDateTimeparseStringToDateTime(String time,String format){DateTimeFormatter df =DateTimeFormatter.ofPattern(format);returnLocalDateTime.parse(time, df);}