From 02a8a0e41f4aae724f035a5b6ba91c360aa1b951 Mon Sep 17 00:00:00 2001 From: CeDo <cedoogle@gmail.com> Date: 星期四, 10 六月 2021 17:10:17 +0800 Subject: [PATCH] Merge branch 'test_elder_cedoo' into test --- springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DateUtils.java | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 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 e02a10e..abec3c8 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 @@ -594,6 +594,54 @@ } } + /** + * 日期相加减 + * @param time + * 时间字符串 yyyy-MM-dd HH:mm:ss + * @param num + * 加的数,-num就是减去 + * @return + * 减去相应的数量的年的日期 + * @throws ParseException + */ + public static Date yearAddNum(Date time, Integer num) { + //SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + //Date date = format.parse(time); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(time); + calendar.add(Calendar.YEAR, num); + Date newTime = calendar.getTime(); + return newTime; + } + + /** + * 将日期对象格式化成yyyy-MM-dd格式的字符串 + * + * @param date 日期对象 + * @return String + */ + public static String getDateStringYMD(Date date) { + + String dateString = ""; + if (date != null) { + dateString = yyyyMMdd_format.format(date); + } + return dateString; + } + + /** + * 获取当前月第一天 + * @return + */ + public static Date getFirstDayOfMonth() { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MONTH,0); + int actualMinimum = cal.getActualMinimum(Calendar.DAY_OF_MONTH); + cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY),actualMinimum,00,00,00); + return cal.getTime(); + } + @@ -602,6 +650,7 @@ // Date date= new Date(); // Date after = new Date(); // System.out.println(calTimeDifference(date,after)); + System.out.println(getFirstDayOfMonth()); } } -- Gitblit v1.7.1