jdk8中奖Date转换为String格式的方法

时间:2022-03-29 12:08:21

public static String getLocalDateStr(Date date,String formatter) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(formatter); Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId);
String dateStr = dateTimeFormatter.format(localDateTime); return dateStr;
}