| | |
| | | import java.lang.management.ManagementFactory; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.ZonedDateTime; |
| | | import java.util.Date; |
| | | import org.apache.commons.lang3.time.DateFormatUtils; |
| | | |
| | |
| | | // long sec = diff % nd % nh % nm / ns; |
| | | return day + "天" + hour + "小时" + min + "分钟"; |
| | | } |
| | | |
| | | public static String parseDateToStrLocal(String dateFormate, LocalDateTime checkDate) { |
| | | // Step 1: 将 LocalDateTime 转换为 ZonedDateTime |
| | | ZonedDateTime zonedDateTime = checkDate.atZone(ZoneId.systemDefault()); |
| | | |
| | | // Step 2: 将 ZonedDateTime 转换为 Instant |
| | | Instant instant = zonedDateTime.toInstant(); |
| | | |
| | | // Step 3: 获取自 Unix 纪元以来的毫秒数 |
| | | long epochMilli = instant.toEpochMilli(); |
| | | return DateFormatUtils.format(epochMilli, dateFormate); |
| | | } |
| | | } |