| | |
| | | |
| | | public static Date getNextMonthFirstDate(String curDate) { |
| | | Date date = DateUtil.getDateFromStringB(curDate); |
| | | return getNextMonthFirstDate(date); |
| | | } |
| | | |
| | | public static Date getNextMonthFirstDate(Date curDate) { |
| | | |
| | | return getNextMonthFirstDate(curDate,1); |
| | | } |
| | | |
| | | public static Date getNextMonthFirstDate(Date curDate,int monthCount) { |
| | | |
| | | Calendar curDateCal = Calendar.getInstance(); |
| | | curDateCal.setTime(date); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.add(Calendar.MONTH, 1); |
| | | return calendar.getTime(); |
| | | curDateCal.setTime(curDate); |
| | | curDateCal.set(Calendar.DAY_OF_MONTH, 1); |
| | | curDateCal.set(Calendar.HOUR_OF_DAY, 0); |
| | | curDateCal.set(Calendar.MINUTE, 0); |
| | | curDateCal.set(Calendar.SECOND, 0); |
| | | curDateCal.add(Calendar.MONTH, monthCount); |
| | | return curDateCal.getTime(); |
| | | } |
| | | |
| | | public static Date getFirstDate() { |
| | |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | public static boolean sameMonthDay(Date startDate,Date endDate){ |
| | | public static boolean sameMonthDay(Date startDate, Date endDate) { |
| | | Calendar startCalendar = Calendar.getInstance(); |
| | | startCalendar.setTime(startDate); |
| | | Calendar endCalender = Calendar.getInstance(); |
| | | endCalender.setTime(endDate); |
| | | if(startCalendar.get(Calendar.DAY_OF_MONTH) == endCalender.get(Calendar.DAY_OF_MONTH)){ |
| | | if ( |
| | | startCalendar.get(Calendar.DAY_OF_MONTH) == endCalender.get(Calendar.DAY_OF_MONTH) |
| | | && startCalendar.get(Calendar.HOUR_OF_DAY) == endCalender.get(Calendar.HOUR_OF_DAY) |
| | | ) { |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 计算 fromDate 2023-01-12 toDate 2023-09-15 |
| | |
| | | Calendar fromDateCal = Calendar.getInstance(); |
| | | fromDateCal.setTime(fromDate); |
| | | fromDateCal.set(Calendar.DAY_OF_MONTH, 1); |
| | | fromDateCal.set(Calendar.HOUR_OF_DAY,0); |
| | | fromDateCal.set(Calendar.MINUTE,0); |
| | | if (fromDate.getTime() > fromDateCal.getTime().getTime()) { |
| | | fromDateCal.add(Calendar.MONTH, 1); |
| | | firstDay = false; |
| | |
| | | Calendar toDateCal = Calendar.getInstance(); |
| | | toDateCal.setTime(toDate); |
| | | toDateCal.set(Calendar.DAY_OF_MONTH, 1); |
| | | toDateCal.set(Calendar.HOUR_OF_DAY,0); |
| | | toDateCal.set(Calendar.MINUTE,0); |
| | | |
| | | if (toDate.getTime() > toDateCal.getTime().getTime()) { |
| | | toDateFirstDate = toDateCal.getTime(); |
| | | } |
| | |
| | | return resMonth.doubleValue(); |
| | | |
| | | } |
| | | |
| | | public static Date getTargetEndTime(double month, Date startDate) { |
| | | Calendar endDate = Calendar.getInstance(); |
| | | endDate.setTime(startDate); |
| | | |
| | | Double intMonth = Math.floor(month); |
| | | endDate.add(Calendar.MONTH, intMonth.intValue()); |
| | | double doubleMonth = month - intMonth; |
| | | if (doubleMonth <= 0) { |
| | | return endDate.getTime(); |
| | | } |
| | | int futureDay = endDate.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | Double hour = doubleMonth * futureDay * 24; |
| | | endDate.add(Calendar.HOUR_OF_DAY, hour.intValue()); |
| | | return endDate.getTime(); |
| | | } |
| | | } |