| | |
| | | * @param year 年份 |
| | | * @return Date |
| | | */ |
| | | public static String getYearFirst(int year){ |
| | | public static String getYearFirst(Integer year){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.clear(); |
| | | calendar.set(Calendar.YEAR, year); |
| | |
| | | * @param year 年份 |
| | | * @return Date |
| | | */ |
| | | public static String getYearLast(int year){ |
| | | public static String getYearLast(Integer year){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.clear(); |
| | | calendar.set(Calendar.YEAR, year); |
| | |
| | | * @param month 年份 |
| | | * @return Date |
| | | */ |
| | | public static String getMonthFirst(int year ,int month){ |
| | | public static String getMonthFirst(Integer year ,Integer month){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.clear(); |
| | | calendar.set(Calendar.YEAR, year); |
| | | calendar.set(Calendar.MONTH, month); |
| | | calendar.set(Calendar.MONTH, month-1); |
| | | Date currYearFirst = calendar.getTime(); |
| | | return formatDate(currYearFirst); |
| | | } |
| | |
| | | * @param month 年份 |
| | | * @return Date |
| | | */ |
| | | public static String getMonthLast(int year ,int month){ |
| | | public static String getMonthLast(Integer year ,Integer month){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.clear(); |
| | | calendar.set(Calendar.YEAR, year); |
| | | calendar.set(Calendar.MONTH, month); |
| | | calendar.set(Calendar.MONTH, month-1); |
| | | calendar.roll(Calendar.DAY_OF_MONTH, -1); |
| | | Date currYearLast = calendar.getTime(); |
| | | |
| | |
| | | Calendar date = Calendar.getInstance(); |
| | | int year = date.get(Calendar.YEAR); |
| | | int month = date.get(Calendar.MONTH); |
| | | System.out.println(getMonthLast(year,month)); |
| | | System.out.println(getMonthLast(year,2)); |
| | | } |
| | | } |