From ad6dfb8323ab40ca8fe4fed94722c755d89c3203 Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期三, 28 二月 2024 15:14:47 +0800 Subject: [PATCH] 整理 --- server/dmvisit_service/src/main/java/com/doumee/core/utils/DateUtil.java | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 54 insertions(+), 1 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 c9be133..62a16ad 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 @@ -58,6 +58,23 @@ } return null; } + /** + * 浼犲叆Data绫诲瀷鏃ユ湡锛岃繑鍥炲瓧绗︿覆绫诲瀷鏃堕棿锛圛SO8601鏍囧噯鏃堕棿锛� + * @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; + }catch (Exception e){ + } + return null; + } public static Date getISO8601DateByStr(String date) { TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); if(date!=null ){ @@ -68,6 +85,25 @@ } //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; @@ -2788,8 +2824,11 @@ public static void main(String[] args) { try { System.out.println(RandomStringUtils.randomNumeric(3)); - Date date = getISO8601DateByStr("2023-02-26T08:59:55.206+08:00"); + Date date = getISO8601DateByStr("2024-02-21T15:46:36.014+08:00"); System.out.println(getISO8601Timestamp(date)); + + + } catch (Exception ex) { ex.printStackTrace(); } @@ -3175,4 +3214,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