|
|
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.common.util.date;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import cn.hutool.core.date.TemporalAccessorUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.enums.DateIntervalEnum;
|
|
|
@@ -19,7 +20,7 @@ import static cn.hutool.core.date.DatePattern.UTC_MS_WITH_XXX_OFFSET_PATTERN;
|
|
|
import static cn.hutool.core.date.DatePattern.createFormatter;
|
|
|
|
|
|
/**
|
|
|
- * 时间工具类,用于 {@link java.time.LocalDateTime}
|
|
|
+ * 时间工具类,用于 {@link LocalDateTime}
|
|
|
*
|
|
|
* @author 芋道源码
|
|
|
*/
|
|
|
@@ -312,4 +313,16 @@ public class LocalDateTimeUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 将给定的 {@link LocalDateTime} 转换为自 Unix 纪元时间(1970-01-01T00:00:00Z)以来的秒数。
|
|
|
+ *
|
|
|
+ * @param sourceDateTime 需要转换的本地日期时间,不能为空
|
|
|
+ * @return 自 1970-01-01T00:00:00Z 起的秒数(epoch second)
|
|
|
+ * @throws NullPointerException 如果 {@code sourceDateTime} 为 {@code null}
|
|
|
+ * @throws DateTimeException 如果转换过程中发生时间超出范围或其他时间处理异常
|
|
|
+ */
|
|
|
+ public static Long toEpochSecond(LocalDateTime sourceDateTime) {
|
|
|
+ return TemporalAccessorUtil.toInstant(sourceDateTime).getEpochSecond();
|
|
|
+ }
|
|
|
+
|
|
|
}
|