From 4a64c0801f147536ed0a9d09977941f313a286ae Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Fri, 18 Aug 2023 16:19:02 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into wb --- screen-common/src/main/java/com/moral/util/DateUtils.java | 95 +++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 86 insertions(+), 9 deletions(-) diff --git a/screen-common/src/main/java/com/moral/util/DateUtils.java b/screen-common/src/main/java/com/moral/util/DateUtils.java index 7776593..e725576 100644 --- a/screen-common/src/main/java/com/moral/util/DateUtils.java +++ b/screen-common/src/main/java/com/moral/util/DateUtils.java @@ -80,6 +80,10 @@ * ������������(yyyy-MM-dd HH) * */ public static final String yyyy_MM_dd_HH_EN = "yyyy-MM-dd HH"; + /* + * ������������(MM-dd) + * */ + public static final String MM_dd_EN = "MM-dd"; /* * Date���toString������ @@ -503,6 +507,14 @@ } } + public static boolean isTimeBeforE(Date nows, Date date) { + long hous = nows.getTime() - date.getTime(); + if (hous >= 0) { + return true; + } else { + return false; + } + } /** * ������������������������������������������������������ * @@ -618,6 +630,22 @@ return dateToDateString(now.getTime(), formatStr); } + + /** + * ������������������day���������������(formatStr)������������ + * + * @param date + * @param date, + * @param hours + * @return + */ + public static Date getDateAddHour(Date date,int hours) { + Calendar now = Calendar.getInstance(TimeZone.getDefault()); + now.setTime(date); + now.add(Calendar.HOUR_OF_DAY, hours); + return now.getTime(); + } + /** * @Description: ������������������day��������������� * @Param: [date, day] @@ -650,6 +678,8 @@ } return new Date(); } + + public static String getAfterNDays(Date date, int n, String formateStr) { SimpleDateFormat sdf = new SimpleDateFormat(formateStr); @@ -956,9 +986,9 @@ cal.setTime(date); final int last = cal.getActualMinimum(Calendar.DAY_OF_YEAR); cal.set(Calendar.DAY_OF_YEAR, last); - cal.set(Calendar.HOUR_OF_DAY,0); - cal.set(Calendar.MINUTE,0); - cal.set(Calendar.SECOND,0); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); return cal.getTime(); } @@ -977,16 +1007,16 @@ } /* - * ��������������������������������� - * */ - public static Date getFirstDayOfMonth(Date date){ + * ��������������������������������� + * */ + public static Date getFirstDayOfMonth(Date date) { final Calendar cal = Calendar.getInstance(); cal.setTime(date); final int last = cal.getActualMinimum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, last); - cal.set(Calendar.HOUR_OF_DAY,0); - cal.set(Calendar.MINUTE,0); - cal.set(Calendar.SECOND,0); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); return cal.getTime(); } @@ -1017,6 +1047,19 @@ return year == currentYear; } + /* + * ��������������������������� + * */ + public static boolean isCurrentMonth(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + int currentYear = cal.get(Calendar.MONTH); + cal.setTime(date); + int year = cal.get(Calendar.MONTH); + return year == currentYear; + } + + /** * ������������������������������ * @@ -1024,6 +1067,14 @@ */ public static Date getLastDayOfCurrMonth() { Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MONTH, 1); + cal.set(Calendar.DAY_OF_MONTH, 0); + return getDate(dateToDateString(cal.getTime(), yyyy_MM_dd_EN)); + } + + public static Date getLastDayOfCurrMonth(Date time) { + Calendar cal = Calendar.getInstance(); + cal.setTime(time); cal.add(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 0); return getDate(dateToDateString(cal.getTime(), yyyy_MM_dd_EN)); @@ -1431,6 +1482,14 @@ return calendar.getTime(); } + //������������ + public static Date addYears(Date date, int years) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.YEAR, years); + return calendar.getTime(); + } + /** * <p> * Title: getDays @@ -1796,4 +1855,22 @@ String lastYear = getDateAddYear(DateUtils.dateToDateString(getDate(), DateUtils.yyyy), -1); return DateUtils.getDate(lastYear, DateUtils.yyyy); } + + //��������������������������������������������������� + public static Map<Date, List<Integer>> getBeforeAndAfterHourDate(Date date) { + String s = dateToDateString(date, yyyy_MM_dd_EN); + List<String> timeLag = getTimeLag(s); + Map<Date, List<Integer>> result = new HashMap<>(); + for (String s1 : timeLag) { + List<Integer> objects = new ArrayList<>(); + Date current = getDate(s1, yyyy_MM_dd_HH_EN); + Date before = addHours(current, -1); + Date after = addHours(current, 1); + objects.add(getHour(before)); + objects.add(getHour(current)); + objects.add(getHour(after)); + result.put(current, objects); + } + return result; + } } -- Gitblit v1.8.0