| | |
| | | } |
| | | |
| | | public static int compareDate(String format, String str1, Date date2) { |
| | | |
| | | Date date1 = null; |
| | | try { |
| | | date1 = fromStringToDate(format, str1); |
| | | } catch (ParseException e) { |
| | | } catch (Exception e) { |
| | | // TODO 自动生成 catch 块 |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | return new Timestamp(System.currentTimeMillis()); |
| | | } |
| | | } |
| | | public static Date getDateFromString2(String strDate) { |
| | | if (StringUtils.isEmpty(strDate)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return sdfLongTimePlus.parse(strDate); |
| | | } catch (Exception ex) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | // ----------------------------------------------------------------------- |
| | |
| | | |
| | | stringDate = getFomartDate(new Date(now), formate); |
| | | |
| | | } catch (ParseException e) { |
| | | } catch (Exception e) { |
| | | |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | long now = date.getTime() + (long) Integer.parseInt(days) * DAY_IN_MILLISECOND; |
| | | |
| | | date = new Date(now); |
| | | |
| | | } catch (ParseException e) { |
| | | } catch (Exception e) { |
| | | |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | * |
| | | * 字符串形式转化为Date类型 String类型按照format格式转为Date类型 |
| | | **/ |
| | | public static Date fromStringToDate(String format, String dateTime) throws ParseException { |
| | | public static Date fromStringToDate(String format, String dateTime) { |
| | | Date date = null; |
| | | SimpleDateFormat sdf = new SimpleDateFormat(format); |
| | | date = sdf.parse(dateTime); |
| | | try { |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat(format); |
| | | date = sdf.parse(dateTime); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | |
| | | return date; |
| | | } |
| | | |
| | |
| | | |
| | | public static void main(String[] args) { |
| | | try { |
| | | Date date = getISO8601DateByStr("2024-04-15T07:46:36.014+08:00"); |
| | | Date date1 = getISO8601DateByStr("2024-06-14T08:46:36.014+08:00"); |
| | | System.out.println(daysBetweenDates11(date1,date)+1); |
| | | // Date date = getISO8601DateByStr("2024-04-15T07:46:36.014+08:00"); |
| | | // Date date1 = getISO8601DateByStr("2024-06-14T08:46:36.014+08:00"); |
| | | System.out.println(DateUtil.afterMinutesDate(-5)); |
| | | |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * X 分钟后时间 |
| | | * @param minutes |
| | | * @return |
| | | */ |
| | | public static Date afterMinutesDate(Date date,Integer minutes){ |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(date); |
| | | cal.add(Calendar.MINUTE,minutes); |
| | | return cal.getTime(); |
| | | } |
| | | |
| | | /** |
| | | * LocalDateTime to date |
| | | * @param now |
| | | * @return |