| | |
| | | * @return String |
| | | * @throws Exception |
| | | */ |
| | | public static String getNowYear() throws Exception { |
| | | public static String getNowYear() { |
| | | String nowYear = ""; |
| | | try { |
| | | String strTemp = getNowLongTime(); |
| | | nowYear = strTemp.substring(0, 4); |
| | | return nowYear; |
| | | } catch (Exception e) { |
| | | throw e; |
| | | e.printStackTrace(); |
| | | } |
| | | return nowYear; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return String |
| | | * @throws Exception |
| | | */ |
| | | public static String getNowMonth() throws Exception { |
| | | public static Integer getNowMonth() { |
| | | String nowMonth = ""; |
| | | try { |
| | | String strTemp = getNowLongTime(); |
| | | nowMonth = strTemp.substring(4, 6); |
| | | return nowMonth; |
| | | return Integer.valueOf(nowMonth); |
| | | } catch (Exception e) { |
| | | throw e; |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return String |
| | | * @throws Exception |
| | | */ |
| | | public static String getNowDay() throws Exception { |
| | | public static String getNowDay() { |
| | | String nowDay = ""; |
| | | try { |
| | | String strTemp = getNowLongTime(); |
| | | nowDay = strTemp.substring(6, 8); |
| | | return nowDay; |
| | | } catch (Exception e) { |
| | | throw e; |
| | | e.printStackTrace(); |
| | | } |
| | | return nowDay; |
| | | } |
| | | |
| | | /** |
| | |
| | | // System.out.println(DateUtil.afterMinutesDate(-5)); |
| | | |
| | | |
| | | System.out.println(getPlusTime2(DateUtil.addMonthToDate(new Date(),-1))); |
| | | // System.out.println(DateUtil.getBeforMonthStr(new Date(),12)); |
| | | // List<String> s = DateUtil.getDayByMonth(); |
| | | // System.out.println(getPlusTime2(DateUtil.addMonthToDate(new Date(),-1))); |
| | | System.out.println(DateUtil.getNowMonth()); |
| | | |
| | | // List<Date> list =getThisMonthDateList(); |
| | | // for(Date d :list){ |
| | |
| | | return cal.getTime(); |
| | | } |
| | | |
| | | public static Date afterHoursDate(Date date,Integer hours){ |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(date); |
| | | cal.add(Calendar.HOUR,hours); |
| | | return cal.getTime(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * LocalDateTime to date |
| | | * @param now |
| | |
| | | cal.set(Calendar.DATE, 1); |
| | | return getDayStartTime(cal.getTime()); |
| | | } |
| | | public static Date getBeginDayOfSeason(int addYears) { |
| | | Integer nowMonth = getNowMonth(); |
| | | int month = Calendar.JANUARY; |
| | | Integer quarter = (nowMonth - 1) / 3 + 1;//季度 |
| | | if(quarter == 2){ |
| | | month = Calendar.APRIL; |
| | | }else if(quarter == 3){ |
| | | month = Calendar.JUNE; |
| | | }else if(quarter == 4){ |
| | | month = Calendar.OCTOBER; |
| | | } |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.set(Calendar.YEAR, getNowYearNum()+addYears); |
| | | cal.set(Calendar.MONTH, month); |
| | | cal.set(Calendar.DATE, 1); |
| | | return getDayStartTime(cal.getTime()); |
| | | } |
| | | |
| | | // 获取本年的结束时间 |
| | | public static Date getEndDayOfYear(int addYears){ |