|  |  | 
 |  |  |         try { | 
 |  |  |             TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); | 
 |  |  |             //TimeZone tz = TimeZone.getTimeZone("GMT-01"); | 
 |  |  |             DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'+'z"); | 
 |  |  |             DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'+'08:00"); | 
 |  |  |             df.setTimeZone(tz); | 
 |  |  |             String nowAsISO = df.format(date); | 
 |  |  |             return nowAsISO; | 
 |  |  |         }catch (Exception e){ | 
 |  |  |         } | 
 |  |  |         return  null; | 
 |  |  |     } | 
 |  |  |     /** | 
 |  |  |      * 传入Data类型日期,返回字符串类型时间(ISO8601标准时间) | 
 |  |  |      * @param date | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public static String getISO8601Timestamp2(Date date){ | 
 |  |  |         try { | 
 |  |  |             TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); | 
 |  |  |             //TimeZone tz = TimeZone.getTimeZone("GMT-01"); | 
 |  |  |             DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'+'08:00"); | 
 |  |  |             df.setTimeZone(tz); | 
 |  |  |             String nowAsISO = df.format(date); | 
 |  |  |             return nowAsISO; | 
 |  |  | 
 |  |  |         } | 
 |  |  |         //TimeZone tz = TimeZone.getTimeZone("GMT-01"); | 
 |  |  |         DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); | 
 |  |  | //        DateFormat df = new SimpleDateFormat("2023-12-08 T 09:25:54.698+08:00"); | 
 |  |  |         df.setTimeZone(tz); | 
 |  |  |         Date nowAsISO = null; | 
 |  |  |         try { | 
 |  |  |             nowAsISO = df.parse(date); | 
 |  |  |         } catch (ParseException e) { | 
 |  |  |         } | 
 |  |  |         return nowAsISO; | 
 |  |  |     } | 
 |  |  |     public static Date getISO8601DateByStr2(String date)  { | 
 |  |  |         TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); | 
 |  |  |         if(date!=null ){ | 
 |  |  |             int i = date.indexOf("+"); | 
 |  |  |             if(i >0){ | 
 |  |  |                 date = date.substring(0,i); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         //TimeZone tz = TimeZone.getTimeZone("GMT-01"); | 
 |  |  |         DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); | 
 |  |  | //        DateFormat df = new SimpleDateFormat("2023-12-08 T 09:25:54.698+08:00"); | 
 |  |  |         df.setTimeZone(tz); | 
 |  |  |         Date nowAsISO = null; | 
 |  |  | 
 |  |  |  | 
 |  |  |         if (date == null) | 
 |  |  |             return ""; | 
 |  |  |         try { | 
 |  |  |             String nowDate = sdfLong.format(date); | 
 |  |  |             return nowDate; | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |         } | 
 |  |  |         return ""; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static String getShortTimeToNull(Date date) { | 
 |  |  |  | 
 |  |  |         if (date == null) | 
 |  |  |             return null; | 
 |  |  |         try { | 
 |  |  |             String nowDate = sdfLong.format(date); | 
 |  |  |             return nowDate; | 
 |  |  | 
 |  |  |         } | 
 |  |  |         int nday = caln.get(Calendar.DAY_OF_YEAR); | 
 |  |  |         days = days + nday - oday; | 
 |  |  |  | 
 |  |  |         return days; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |     public static void main(String[] args) { | 
 |  |  |         try { | 
 |  |  |             System.out.println(RandomStringUtils.randomNumeric(3)); | 
 |  |  |             Date date = getISO8601DateByStr("2023-02-26T08:59:55.206+08:00"); | 
 |  |  |             System.out.println(getISO8601Timestamp(date)); | 
 |  |  |             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); | 
 |  |  |  | 
 |  |  |         } catch (Exception ex) { | 
 |  |  |             ex.printStackTrace(); | 
 |  |  |         } | 
 |  |  | 
 |  |  |         } | 
 |  |  |         return week; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 时间转义带时区   入参格式      2022-09-13T00:53:03.000+00:00 | 
 |  |  |      * @param timeEscape | 
 |  |  |      * @return | 
 |  |  |      * @throws ParseException | 
 |  |  |      */ | 
 |  |  |     public static String timeEscape(String timeEscape) throws ParseException { | 
 |  |  |         SimpleDateFormat startDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX", Locale.US); | 
 |  |  |         SimpleDateFormat startDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
 |  |  |         String time = startDateFormat1.format(startDateFormat.parse(timeEscape)); | 
 |  |  |         System.out.println(time); | 
 |  |  |         return time; | 
 |  |  |     } | 
 |  |  | } |