| | |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | // Date date= new Date(); |
| | | // Date after = new Date(); |
| | | // System.out.println(getFirstDayOfMonthString()); |
| | | // System.out.println(getDayOfMonthString()); |
| | | Date date= getLastMonthFirst(); |
| | | Date after = getLastMonthEnd(); |
| | | System.out.println(date); |
| | | System.out.println(after); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | Date currYearFirst = calendar.getTime(); |
| | | return currYearFirst; |
| | | } |
| | | |
| | | /** |
| | | * 获取上月第一天时间 |
| | | * @return 上月第一天时间 |
| | | */ |
| | | public static Date getLastMonthFirst(){ |
| | | // 上月起始 |
| | | Calendar lastMonthFirstDateCal = Calendar.getInstance(); |
| | | lastMonthFirstDateCal.add(Calendar.MONTH,-1); |
| | | lastMonthFirstDateCal.set(Calendar.DAY_OF_MONTH, 1); |
| | | String lastMonthFirstTime = yyyyMMdd_format.format(lastMonthFirstDateCal.getTime()) + " 00:00:00"; |
| | | return stringToDateStandard(lastMonthFirstTime); |
| | | } |
| | | |
| | | /** |
| | | * 获取上月最后一天时间 |
| | | * @return 最后一天时间 |
| | | */ |
| | | public static Date getLastMonthEnd(){ |
| | | // 上月末尾 |
| | | Calendar lastMonthEndDateCal = Calendar.getInstance(); |
| | | lastMonthEndDateCal.add(Calendar.MONTH,-1); |
| | | lastMonthEndDateCal.set(Calendar.DAY_OF_MONTH, lastMonthEndDateCal.getActualMaximum(Calendar.DAY_OF_MONTH)); |
| | | String lastMonthEndTime = yyyyMMdd_format.format(lastMonthEndDateCal.getTime()) + " 23:59:59"; |
| | | return stringToDateStandard(lastMonthEndTime); |
| | | } |
| | | } |