1 public static String specialFormatDateSplicing(Date date) { 2 if (date == null) { 3 return null; 4 } 5 LocalDateTime localDateTime = convertDateToLocalDateTime(date); 6 LocalDate now = LocalDate.now(); 7 if (!localDateTime.isBefore(now.atStartOfDay())) { 8 return DateTimeFormatter.ofPattern("今天 HH:mm:ss").format(localDateTime); 9 } else if (!localDateTime.isBefore(now.minusDays(1).atStartOfDay())) { 10 return DateTimeFormatter.ofPattern("昨天 HH:mm:ss").format(localDateTime); 11 } else if (!localDateTime.isBefore(now.minusDays(2).atStartOfDay())) { 12 return DateTimeFormatter.ofPattern("前天 HH:mm:ss").format(localDateTime); 13 } else { 14 return DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss").format(localDateTime); 15 } 16 } 17 18 public static String specialFormatDateNext(Date date) { 19 if (date == null) { 20 return null; 21 } 22 LocalDateTime localDateTime = convertDateToLocalDateTime(date); 23 if (DateUtil.date2String(date, DateUtil.FORMAT_DATE).equals(DateUtil.date2String(new Date(), DateUtil.FORMAT_DATE))) { 24 return DateTimeFormatter.ofPattern("今天 HH:mm:ss").format(localDateTime); 25 } else if (DateUtil.getDayDiff(new Date(), date) < 2) { 26 return DateTimeFormatter.ofPattern("明天 HH:mm:ss").format(localDateTime); 27 } else if (DateUtil.getDayDiff(new Date(), date) < 3) { 28 return DateTimeFormatter.ofPattern("后天 HH:mm:ss").format(localDateTime); 29 } else { 30 return DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss").format(localDateTime); 31 } 32 }
标签:后天,return,ofPattern,展示,format,前天,DateTimeFormatter,localDateTime,date From: https://www.cnblogs.com/yxl-wyb/p/16880722.html