From a9129b96fa14c77df166f367be1d8220c8f9d0b7 Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期六, 19 一月 2019 15:14:04 +0800 Subject: [PATCH] 用户等级+用户设置 --- utils/src/main/java/org/yeshi/utils/DateUtil.java | 91 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 90 insertions(+), 1 deletions(-) diff --git a/utils/src/main/java/org/yeshi/utils/DateUtil.java b/utils/src/main/java/org/yeshi/utils/DateUtil.java index 10e3174..3cfbc90 100644 --- a/utils/src/main/java/org/yeshi/utils/DateUtil.java +++ b/utils/src/main/java/org/yeshi/utils/DateUtil.java @@ -2,8 +2,10 @@ import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.List; public class DateUtil { @@ -92,12 +94,48 @@ return false; } } + + + /** + * 楠岃瘉鏄惁灞炰簬鍚屼竴澶� + * + * @param Date1 + * @param Date2 + * @return + */ + public static boolean isSameMonth(Date date1, Date date2) { + if (date1 != null && date2 != null) { + Calendar cal1 = Calendar.getInstance(); + cal1.setTime(date1); + Calendar cal2 = Calendar.getInstance(); + cal2.setTime(date2); + return isSameMonth(cal1, cal2); + } else { + return false; + } + } + + /** + * 楠岃瘉鏄惁灞炰簬鍚屽勾鍚屾湀 + * + * @param cal1 + * @param cal2 + * @return + */ + public static boolean isSameMonth(Calendar cal1, Calendar cal2) { + if (cal1 != null && cal2 != null) { + return cal1.get(0) == cal2.get(0) && cal1.get(1) == cal2.get(1) && cal1.get(6) == cal2.get(6); + } else { + return false; + } + } + /** * 鎸囧畾鏃ユ湡鍔犱笂澶╂暟鍚庣殑鏃ユ湡 * * @param num - * 涓哄鍔犵殑澶╂暟 + * 澧炲姞鐨勫ぉ鏁� * @param nowDate * 鍒涘缓鏃堕棿 * @return @@ -113,4 +151,55 @@ return format.format(ca.getTime()); } + + /** + * 鎸囧畾鏃ユ湡鍑忓幓澶╂暟鍚庣殑鏃ユ湡 + * + * @param num + * 鍑忓幓鐨勫ぉ鏁� + * @param nowDate + * 鍒涘缓鏃堕棿 + * @return + * @throws ParseException + */ + public static String reduceDay(int num, String nowDate) throws ParseException { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + Date currdate = format.parse(nowDate); + + Calendar ca = Calendar.getInstance(); + ca.setTime(currdate); + ca.add(Calendar.DATE, -num); // 鏃ユ湡鍑� 濡傛灉涓嶅鍑忎細灏嗘湀鍙樺姩 + + return format.format(ca.getTime()); + } + + /** + * 杩斿洖涓棿鏃ユ湡 + * @param startTime + * @param endTime + * @return + * @throws Exception + */ + public static List<String> dayFactory(String startTime, String endTime) throws Exception { + + List<String> listDate = new ArrayList<String>(); + + String plusDay = ""; + for (int i = 0; i < 1000; i++) { + if (i == 0) { + plusDay = startTime; + } else { + plusDay = DateUtil.plusDay(i, startTime); + } + + listDate.add(plusDay); + + if (plusDay.equals(endTime)) { + break; // 鏃堕棿缁撴潫 + } + } + + return listDate; + } + } \ No newline at end of file -- Gitblit v1.8.0