From 206aa4bf5fd44e9b31d7284d6be8dc60b90a73ae Mon Sep 17 00:00:00 2001
From: huanghongfa <huanghongfa123456>
Date: 星期二, 22 二月 2022 18:12:04 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/DateUtils.java | 123 ++++++++++++++++++++++++++++++----------
1 files changed, 91 insertions(+), 32 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 6b14d69..4165ba5 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
@@ -26,6 +26,7 @@
public static SimpleDateFormat yyyyMM_format = new SimpleDateFormat("yyyy-MM");
public static SimpleDateFormat format_yyymmdd = new SimpleDateFormat("yyyyMMdd");
public static SimpleDateFormat format_yyyy = new SimpleDateFormat("yyyy");
+ public static SimpleDateFormat format_yyyyMMddHHmmss = new SimpleDateFormat("yyyyMMddHHmmss");
private static DateTimeFormatter format_ymdhmssss = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
private static DateTimeFormatter format_ymds = DateTimeFormatter.ofPattern("yyyyMMdd");
private static DateTimeFormatter format_yms = DateTimeFormatter.ofPattern("yyyyMM");
@@ -52,7 +53,7 @@
/**
* 字符串转date
- *
+ *
* @param date
* 时间戳
* @param format
@@ -73,7 +74,7 @@
/**
* 字符串转date
- *
+ *
* @param date
* 时间戳
* @return 时间
@@ -99,7 +100,7 @@
/**
* 字符串转date
- *
+ *
* @param date
* 时间戳
* @return 时间
@@ -118,7 +119,7 @@
/**
* 获取当前时间
- *
+ *
* @return
* @throws Exception
*/
@@ -129,7 +130,7 @@
/**
* 返回当前事件的时间戳
- *
+ *
* @return
*/
public static Long getCurrentDateTimeStamp() {
@@ -138,7 +139,7 @@
/**
* 获取当前时间字符串,格式为yyyy-MM-dd HH:mm:ss
- *
+ *
* @return
*/
public static String getCurrentDateStr() {
@@ -158,7 +159,7 @@
/**
* 获取当前时间字符串,格式为yyyyMMdd
- *
+ *
* @return
*/
public static String getCurrentDateString() {
@@ -168,7 +169,7 @@
/**
* 获取当前时间字符串,格式为yyyy-MM-dd
- *
+ *
* @return
*/
public static String getCurrentDateStrymd() {
@@ -183,7 +184,7 @@
/**
* 获取当前时间long值
- *
+ *
* @return
*/
public static long getCurrentDataLong() {
@@ -192,7 +193,7 @@
/**
* 获取当前时间
- *
+ *
* @param format
* @return
* @throws Exception
@@ -297,7 +298,7 @@
/**
* 对日期进行加法操作
- *
+ *
* @param date
* @param hours
* @return
@@ -314,7 +315,7 @@
/**
* 对日期的分钟进行加法操作
- *
+ *
* @param date
* @param minutes
* @return
@@ -389,7 +390,7 @@
/**
* 计算两个日期先差多少秒
- *
+ *
* @param pre
* 前一个日期
* @param after
@@ -402,7 +403,7 @@
/**
* 计算两个时间相差的天数
- *
+ *
* @param stardate
* @param enddate
* @return
@@ -424,7 +425,7 @@
/**
* 结束时间与当前时间计算相差的月数
- *
+ *
* @param enddate
* @return
*/
@@ -443,7 +444,7 @@
/**
* 获取某个时间段之前的时间点
- *
+ *
* @return
*/
public static String getSomeTimeStapStr(String sign) {
@@ -488,7 +489,7 @@
/**
* 获取失效时间点(在什么时间失效)
- *
+ *
* @param minutes
* 有效分钟数
* @return
@@ -499,7 +500,7 @@
/**
* 获取当前年份
- *
+ *
* @return
*/
public static String getCurrentYear() {
@@ -509,7 +510,7 @@
/**
* 获取当前月份
- *
+ *
* @return
*/
public static String getCurrentMonth() {
@@ -526,7 +527,7 @@
/**
* 获取无符号的当前时间
- *
+ *
* @return
*/
public static String getCurrentDateStrNoSignal() {
@@ -535,7 +536,7 @@
/**
* 获取前几个小时的时间
- *
+ *
* @param hours
* @return
*/
@@ -551,7 +552,7 @@
/**
* 小时取整
- *
+ *
* @param date
* @param hour
* @return
@@ -572,7 +573,7 @@
/**
* 分钟取整 以十分钟为单位 ,去除尾端,加上 参数 46->40+minutes*10
- *
+ *
* @param date
* @param minutes
* @return
@@ -600,7 +601,7 @@
/**
* 天数取整
- *
+ *
* @param date
* @param day
* @return
@@ -621,7 +622,7 @@
/**
* 日期相加减
- *
+ *
* @param time
* 时间字符串 yyyy-MM-dd HH:mm:ss
* @param num
@@ -683,7 +684,7 @@
/**
* 获取当前月第一天
- *
+ *
* @return
*/
public static Date getFirstDayOfMonth() {
@@ -696,7 +697,7 @@
/**
* 获取当前年月的第一天时间
- *
+ *
* @param year
* 年份
* @param month
@@ -720,7 +721,7 @@
/**
* 获取当前年月的最后一天时间
- *
+ *
* @param year
* 年份
* @param month
@@ -780,7 +781,7 @@
/**
* date2比date1多的天数
- *
+ *
* @param date1
* @param date2
* @return
@@ -818,8 +819,28 @@
}
/**
+ * 计算剩余天数,不足一天按一天算
+ * @param expireDate
+ * @return
+ */
+ public static int retrieveRemainingDays(Date expireDate) {
+ Date nowDate = new Date();
+ Calendar startDate = Calendar.getInstance();
+ startDate.setTime(nowDate);
+ Calendar endDate = Calendar.getInstance();
+ endDate.setTime(expireDate);
+ Calendar date = (Calendar) startDate.clone();
+ int daysBetween = 0;
+ while (date.before(endDate)) {
+ date.add(Calendar.DAY_OF_MONTH, 1);
+ daysBetween++;
+ }
+ return daysBetween;
+ }
+
+ /**
* 获取当前月第一天
- *
+ *
* @return
*/
public static String getFirstDayOfMonthString() {
@@ -835,7 +856,7 @@
/**
* 获取当前月最后一天
- *
+ *
* @return
*/
public static String getLastDayOfMonthString() {
@@ -848,10 +869,25 @@
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(calendar.getTime()) + " 23:59:59";
}
+ /**
+ * 获取当前月最后一天
+ *
+ * @return
+ */
+ public static Date getLastDayOfMonth() {
+ Calendar calendar = Calendar.getInstance();
+
+ calendar.add(Calendar.MONTH, 1);
+
+ calendar.set(Calendar.DAY_OF_MONTH, 0);
+ // 格式化日期
+
+ return calendar.getTime();
+ }
/**
* 获取当前时间(年月日)
- *
+ *
* @return
*/
public static String getDayOfMonthString() {
@@ -979,4 +1015,27 @@
}
return dates;
}
+
+ /**
+ * 获取上月最后一天时间
+ * @return 上月最后一天时间
+ */
+ public static String getOldMonthLastDay(){
+ Calendar calendar=Calendar.getInstance();
+ int month=calendar.get(Calendar.MONTH);
+ calendar.set(Calendar.MONTH, month-1);
+ calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+ return format_yyymmdd.format(calendar.getTime());
+ }
+
+ /**
+ * 获取上月第一天时间
+ * @return 上月第一天时间
+ */
+ public static String getOldMonthFirstDay(){
+ Calendar calendar=Calendar.getInstance();
+ calendar.add(Calendar.MONTH, -1);
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
+ return format_yyymmdd.format(calendar.getTime());
+ }
}
--
Gitblit v1.7.1