| | |
| | | import cn.hutool.core.date.DateUnit; |
| | | import org.apache.commons.lang3.RandomStringUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | /** |
| | | * 日期工具类 |
| | | * @author: jiangping |
| | |
| | | Date nowAsISO = null; |
| | | try { |
| | | nowAsISO = df.parse(date); |
| | | } catch (ParseException e) { |
| | | } catch (Exception e) { |
| | | } |
| | | return nowAsISO; |
| | | } |
| | | |
| | | public static Date getISO8601DateByStr2(String date) { |
| | | TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); |
| | | if(date!=null ){ |
| | |
| | | Date nowAsISO = null; |
| | | try { |
| | | nowAsISO = df.parse(date); |
| | | } catch (ParseException e) { |
| | | } catch (Exception e) { |
| | | } |
| | | return nowAsISO; |
| | | } |
| | |
| | | |
| | | 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(DateUtil.afterMinutesDate(-5)); |
| | | |
| | | System.out.println(DateUtil.getFirstThisMonthDate()); |
| | | |
| | | // System.out.println(getPlusTime2(DateUtil.addMonthToDate(new Date(),-1))); |
| | | // System.out.println(DateUtil.getBeforMonthStr(new Date(),12)); |
| | | |
| | | // List<Date> list =getThisMonthDateList(); |
| | | // for(Date d :list){ |
| | | // System.out.println(getPlusTime2(d)); |
| | | // } |
| | | // List<Date> list1 =getThisYearMonthList(); |
| | | // for(Date d :list1){ |
| | | // System.out.println(getPlusTime2(d)); |
| | | // } |
| | | |
| | | // Date startTime = DateUtil.StringToDate("2024-05-01 08:00:00" ,"yyyy-MM-dd HH:mm:ss"); |
| | | // Date endTime = DateUtil.StringToDate("2024-05-01 17:00:00" ,"yyyy-MM-dd HH:mm:ss"); |
| | | // Long intervalTime = 35L; |
| | | // |
| | | // |
| | | // DateUtil.checkDateInterval( startTime.toInstant() |
| | | // .atZone(ZoneId.systemDefault()) |
| | | // .toLocalDateTime(), endTime.toInstant() |
| | | // .atZone(ZoneId.systemDefault()) |
| | | // .toLocalDateTime(),intervalTime); |
| | | |
| | | System.out.println(getISO8601DateByStr("2025-12-26T03:08:39.123Z")); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |
| | |
| | | String temp = sdf.format(date); |
| | | String firstDayInMoth = ""; |
| | | firstDayInMoth = temp + "-01"; |
| | | |
| | | return firstDayInMoth; |
| | | |
| | | } |
| | |
| | | */ |
| | | public static String getWeekZhouOfDate(Date dt) { |
| | | String[] weekDays = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" }; |
| | | Calendar cal = Calendar.getInstance(); |
| | | TimeZone china = TimeZone.getTimeZone("Asia/Shanghai"); |
| | | Calendar cal = Calendar.getInstance(china); |
| | | cal.setTime(dt); |
| | | |
| | | int w = cal.get(Calendar.DAY_OF_WEEK) - 1; |