jiangping
2025-02-14 c185de12314b8733f23ed7856e6d1e87ee95c1ca
server/services/src/main/java/com/doumee/core/utils/DateUtil.java
@@ -10,6 +10,9 @@
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.*;
@@ -39,7 +42,18 @@
    public DateUtil() {
    }
    public static Date getDateFromLocalDateTime(  LocalDateTime localDateTime) {
        try {
            ZoneId zoneId = ZoneId.systemDefault(); // 获取系统默认时区
            ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId); // 转换为带时区的日期时间
            Date date = Date.from(zonedDateTime.toInstant()); // 转换为Date
            return  date;
        }catch (Exception e){
        }
        return null;
    }
    public static Date StringToDate2(String DATE) {
        if(StringUtils.isBlank(DATE)){
            return null;
@@ -2309,7 +2323,7 @@
    }
    public static Date getDateFromString2(String strDate) {
        if (StringUtils.isEmpty(strDate)) {
            return new Date(System.currentTimeMillis());
            return null;
        }
        try {
            return sdfLongTimePlus.parse(strDate);
@@ -3031,6 +3045,16 @@
        return (int)diff;
    }
    public static Integer betweenSeconds(Date begin, Date end) {
        if(begin ==null ){
            return  0;
        }
        long createTime =begin.getTime();//获取创建时间的时间戳
        long currentTime =Objects.isNull(end)?System.currentTimeMillis():end.getTime();//获取当前时间的时间戳
        long diff=(currentTime-createTime)/1000;//获取两个时间相差的分钟
        return (int)diff;
    }
    /**
     * 计算耗时