huanghongfa
2021-06-23 b057f9985a360fcfeb3aa6e96eae99deccffa1d2
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DateUtils.java
@@ -2,6 +2,7 @@
import lombok.extern.slf4j.Slf4j;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
@@ -617,6 +618,32 @@
        return newTime;
    }
    public static boolean isValidDate(String str) {
        boolean convertSuccess=true;
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        try {
            format.setLenient(false);
            format.parse(str);
        } catch (ParseException e) {
            convertSuccess=false;
        }
        return convertSuccess;
    }
    public static Date toValidDate(String str) {
        Date date = null;
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        try {
            format.setLenient(false);
            date = format.parse(str);
        } catch (ParseException e) {
            log.error("党员导入日期格式错误");
            date = new Date();
        }
        return date;
    }
    /**
     * 将日期对象格式化成yyyy-MM-dd格式的字符串
     *
@@ -721,6 +748,7 @@
    public static void main(String[]args)throws Exception{
        isValidDate("2020/12/4");
//        Date date= new Date();
//        Date after = new Date();
//        System.out.println(calTimeDifference(date,after));