old mode 100644
new mode 100755
| | |
| | | package com.genersoft.iot.vmp.utils; |
| | | |
| | | |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | |
| | | import java.time.Instant; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | |
| | | */ |
| | | public static final String URL_PATTERN = "yyyyMMddHHmmss"; |
| | | |
| | | /** |
| | | * 日期格式 |
| | | */ |
| | | public static final String date_PATTERN = "yyyy-MM-dd"; |
| | | |
| | | public static final String zoneStr = "Asia/Shanghai"; |
| | | |
| | | public static final DateTimeFormatter formatterCompatibleISO8601 = DateTimeFormatter.ofPattern(ISO8601_COMPATIBLE_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); |
| | | public static final DateTimeFormatter formatterISO8601 = DateTimeFormatter.ofPattern(ISO8601_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); |
| | | public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); |
| | | public static final DateTimeFormatter DateFormatter = DateTimeFormatter.ofPattern(date_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); |
| | | public static final DateTimeFormatter urlFormatter = DateTimeFormatter.ofPattern(URL_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); |
| | | |
| | | public static String yyyy_MM_dd_HH_mm_ssToISO8601(String formatTime) { |
| | |
| | | Instant instant = Instant.from(temporalAccessor); |
| | | return instant.getEpochSecond(); |
| | | } |
| | | |
| | | /** |
| | | * 时间戳 转 yyyy_MM_dd_HH_mm_ss |
| | | */ |
| | | public static String timestampTo_yyyy_MM_dd_HH_mm_ss(long timestamp) { |
| | | Instant instant = Instant.ofEpochSecond(timestamp); |
| | | return formatter.format(LocalDateTime.ofInstant(instant, ZoneId.of(zoneStr))); |
| | | } |
| | | |
| | | /** |
| | | * 时间戳 转 yyyy_MM_dd |
| | | */ |
| | | public static String timestampTo_yyyy_MM_dd(long timestamp) { |
| | | Instant instant = Instant.ofEpochMilli(timestamp); |
| | | return DateFormatter.format(LocalDateTime.ofInstant(instant, ZoneId.of(zoneStr))); |
| | | } |
| | | |
| | | /** |
| | | * 获取当前时间 |
| | |
| | | } |
| | | |
| | | public static long getDifferenceForNow(String keepaliveTime) { |
| | | if (ObjectUtils.isEmpty(keepaliveTime)) { |
| | | return 0; |
| | | } |
| | | Instant beforeInstant = Instant.from(formatter.parse(keepaliveTime)); |
| | | return ChronoUnit.MILLIS.between(beforeInstant, Instant.now()); |
| | | } |