From 72f11c9e9edec3d2534112badf7a0ca48fa9da5a Mon Sep 17 00:00:00 2001 From: 罗元桥 <2376770955@qq.com> Date: 星期三, 23 六月 2021 14:37:44 +0800 Subject: [PATCH] Merge branch 'test' into 'test_wangge_two' --- springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DateUtils.java | 36 ++++++++++++++++++++++++++++++++++-- 1 files changed, 34 insertions(+), 2 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DateUtils.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DateUtils.java index deddc1a..74b43ce 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DateUtils.java +++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DateUtils.java @@ -2,6 +2,7 @@ import lombok.extern.slf4j.Slf4j; +import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.*; @@ -125,6 +126,13 @@ return now; } + /** + * 返回当前事件的时间戳 + * @return + */ + public static Long getCurrentDateTimeStamp(){ + return LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); + } /** * 获取当前时间字符串,格式为yyyy-MM-dd HH:mm:ss * @return @@ -617,6 +625,32 @@ return newTime; } + public static boolean isValidDate(String str) { + boolean convertSuccess=true; + SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); + try { + format.setLenient(false); + format.parse(str); + } catch (ParseException e) { + convertSuccess=false; + } + return convertSuccess; + } + + public static Date toValidDate(String str) { + Date date = null; + SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); + try { + format.setLenient(false); + date = format.parse(str); + } catch (ParseException e) { + log.error("党员导入日期格式错误"); + date = new Date(); + } + return date; + } + + /** * 将日期对象格式化成yyyy-MM-dd格式的字符串 * @@ -719,12 +753,10 @@ - public static void main(String[]args)throws Exception{ // Date date= new Date(); // Date after = new Date(); // System.out.println(calTimeDifference(date,after)); - System.out.println(getYearMonthStart(2021,2)); } } -- Gitblit v1.7.1