要使用dateTimeFormatter将LocalDateTime类型转换为String类型:dateTimeFormatter.format(currentTime)
代码如下:
public static void getDay(){
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime currentTime = LocalDateTime.now();
LocalDateTime parse = LocalDateTime.parse( dateTimeFormatter.format(currentTime),dateTimeFormatter);
//当前时间的毫秒数
long times = LocalDateTime.from(parse).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
System.out.println("times = " + times);
}