From 1293d3dba10c4e291dfbce4c936f952875557edb Mon Sep 17 00:00:00 2001 From: lishuai <260038442@qq.com> Date: 星期二, 26 十二月 2023 18:40:49 +0800 Subject: [PATCH] 配置信息对接调整提交 --- server/dmvisit_service/src/main/java/com/doumee/core/utils/DateUtil.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/server/dmvisit_service/src/main/java/com/doumee/core/utils/DateUtil.java b/server/dmvisit_service/src/main/java/com/doumee/core/utils/DateUtil.java index a878604..1a307f1 100644 --- a/server/dmvisit_service/src/main/java/com/doumee/core/utils/DateUtil.java +++ b/server/dmvisit_service/src/main/java/com/doumee/core/utils/DateUtil.java @@ -41,6 +41,43 @@ public DateUtil() { } + /** + * 浼犲叆Data绫诲瀷鏃ユ湡锛岃繑鍥炲瓧绗︿覆绫诲瀷鏃堕棿锛圛SO8601鏍囧噯鏃堕棿锛� + * @param date + * @return + */ + public static String getISO8601Timestamp(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.SSS'+'z"); + df.setTimeZone(tz); + String nowAsISO = df.format(date); + return nowAsISO; + }catch (Exception e){ + } + return null; + } + public static Date getISO8601DateByStr(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.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 StringToDate2(String DATE) { if(StringUtils.isBlank(DATE)){ return null; @@ -2751,6 +2788,8 @@ 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)); } catch (Exception ex) { ex.printStackTrace(); } @@ -3136,4 +3175,18 @@ } 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; + } } \ No newline at end of file -- Gitblit v1.9.3