| | |
| | | public static Date convertToDate(LocalDateTime localDateTime) { |
| | | return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); |
| | | } |
| | | |
| | | //1月/2季度/3年得到开始时间到当前月的结束时间 |
| | | public static Map<String,Date> getStartAndEndTime(Integer sticTime) throws ParseException { |
| | | Map<String,Date> map=new HashMap(); |
| | | // 获取当前时间 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime startDate=now;//默认 |
| | | // 获取本月的最后一天 |
| | | LocalDateTime endtDate=now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59).withNano(0); |
| | | //指定年月获取这个月的开始时间和结束时间 |
| | | if(sticTime==1){ |
| | | startDate=DateUtil.getStartOfMonth(); |
| | | } |
| | | if(sticTime==2){ |
| | | startDate=DateUtil.getStartOfQuarter(); |
| | | } |
| | | if(sticTime==3){ |
| | | startDate=DateUtil.getStartOfYear(); |
| | | } |
| | | map.put("startTime",DateUtil.convertToDate(startDate)); |
| | | map.put("endTime",DateUtil.convertToDate(endtDate)); |
| | | return map; |
| | | } |
| | | } |