| | |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.DateFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.*; |
| | |
| | | public static SimpleDateFormat ymdhms_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | public static DateTimeFormatter format_ymd_String = DateTimeFormatter.ofPattern("yyMMdd"); |
| | | |
| | | public static SimpleDateFormat yyyyMM_format = new SimpleDateFormat("yyyy-MM"); |
| | | |
| | | |
| | | |
| | |
| | | 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格式的字符串 |
| | | * |
| | |
| | | return date1.getTime(); |
| | | } |
| | | |
| | | public static Date parseDateYM(String str) { |
| | | try { |
| | | return yyyyMM_format.parse(str); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public static int getMonth(Date date){ |
| | | Calendar instance = Calendar.getInstance(); |
| | | instance.setTime(date); |
| | |
| | | |
| | | |
| | | 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)); |