huanghongfa
2021-06-09 c0a7fdfcf9f74359fbecf2addc570e13be374dbc
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.*;
@@ -615,14 +616,38 @@
        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;
    }
    public static void main(String[]args)throws Exception{
//        Date date= new Date();
//        Date after = new Date();
//        System.out.println(calTimeDifference(date,after));
        isValidDate("2020/12/4");
    }
}