public class DateTimeFormatUtil { public static String YMD_HMS = "yyyy-MM-dd HH:mm:ss"; public static String YMD_HMS_CN = "yyyy年MM月dd日 HH时mm分ss秒"; public static String YMD = "yyyy-MM-dd"; public static String YMD_HM = "yyyy-MM-dd HH:mm"; public static String MilliSecondToDate(Long milliSecond, String format) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern(format); LocalDateTime dateTime = LocalDateTime.ofEpochSecond(milliSecond / 1000L, 0, ZoneOffset.ofHours(8)); return dtf.format(dateTime); } public static String SecondToDate(Long second, String format) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern(format); LocalDateTime dateTime = LocalDateTime.ofEpochSecond(second, 0, ZoneOffset.ofHours(8)); return dtf.format(dateTime); } public static Long stringTimeToLong(String time, String format) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern(format); LocalDateTime parse = LocalDateTime.parse(time, dtf); return LocalDateTime.from(parse).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); } }