| | |
| | | package com.moral.util; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | |
| | | }} |
| | | } |
| | | |
| | | public static List<String> findDaysStr(String beginTime,String endTime){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | Date dBegin = null; |
| | | Date dEnd = null; |
| | | try { |
| | | dBegin = sdf.parse(beginTime); |
| | | dEnd = sdf.parse(endTime); |
| | | }catch (ParseException e){ |
| | | e.printStackTrace(); |
| | | } |
| | | List<String> daysStrList = new ArrayList<>(); |
| | | daysStrList.add(sdf.format(dBegin)); |
| | | Calendar calBegin = Calendar.getInstance(); |
| | | calBegin.setTime(dBegin); |
| | | Calendar calEnd = Calendar.getInstance(); |
| | | calEnd.setTime(dEnd); |
| | | while (dEnd.after(calBegin.getTime())) { |
| | | calBegin.add(Calendar.DAY_OF_MONTH,1); |
| | | String dayStar = sdf.format(calBegin.getTime()); |
| | | daysStrList.add(dayStar); |
| | | } |
| | | |
| | | return daysStrList; |
| | | } |
| | | |
| | | public static List<String> findHoursStr(String beginTime,String endTime){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date dBegin = null; |
| | | Date dEnd = null; |
| | | try { |
| | | dBegin = sdf.parse(beginTime); |
| | | dEnd = sdf.parse(endTime); |
| | | }catch (ParseException e){ |
| | | e.printStackTrace(); |
| | | } |
| | | List<String> daysStrList = new ArrayList<>(); |
| | | daysStrList.add(sdf.format(dBegin)); |
| | | Calendar calBegin = Calendar.getInstance(); |
| | | calBegin.setTime(dBegin); |
| | | Calendar calEnd = Calendar.getInstance(); |
| | | calEnd.setTime(dEnd); |
| | | while (dEnd.after(calBegin.getTime())) { |
| | | calBegin.add(Calendar.HOUR,1); |
| | | String dayStar = sdf.format(calBegin.getTime()); |
| | | daysStrList.add(dayStar); |
| | | } |
| | | |
| | | return daysStrList; |
| | | } |
| | | |
| | | } |