@Test public void testDateRedMonthEnd() { Date date = DateUtil.parse(DateUtil.YYYY_MM, "201603"); String endDate = DateUtil.dateRedMonthEnd(date, 0); assertEquals(endDate, "2016-03-31"); }
public static String dateRedMonthEnd(Date date, int n) { String str = ""; int year = year(date); int month = month(date); if (n >= 12) { int m = n % 12; int s = n / 12; month = 12 - m + month; year = year - s; } else { month = month - n; } if (month == 0) { year = year - 1; month = 12; } if (month < 10) { str = "0" + month; } else { str = month + ""; } return year + "-" + str + "-" + maxDayOfMonth(year, month); }
DateUtil { public static String dateRedMonthEnd(Date date, int n) { String str = ""; int year = year(date); int month = month(date); if (n >= 12) { int m = n % 12; int s = n / 12; month = 12 - m + month; year = year - s; } else { month = month - n; } if (month == 0) { year = year - 1; month = 12; } if (month < 10) { str = "0" + month; } else { str = month + ""; } return year + "-" + str + "-" + maxDayOfMonth(year, month); } }
DateUtil { public static String dateRedMonthEnd(Date date, int n) { String str = ""; int year = year(date); int month = month(date); if (n >= 12) { int m = n % 12; int s = n / 12; month = 12 - m + month; year = year - s; } else { month = month - n; } if (month == 0) { year = year - 1; month = 12; } if (month < 10) { str = "0" + month; } else { str = month + ""; } return year + "-" + str + "-" + maxDayOfMonth(year, month); }  }
DateUtil { public static String dateRedMonthEnd(Date date, int n) { String str = ""; int year = year(date); int month = month(date); if (n >= 12) { int m = n % 12; int s = n / 12; month = 12 - m + month; year = year - s; } else { month = month - n; } if (month == 0) { year = year - 1; month = 12; } if (month < 10) { str = "0" + month; } else { str = month + ""; } return year + "-" + str + "-" + maxDayOfMonth(year, month); }  static DateFormat getDateFormat(String format); static String format(String format, Date date); static Date parse(String format, String date); static String getDateStr(Date date, String format, int i, int j); static boolean isLeapYear(int year); static int maxDayOfMonth(int year, int month); static int year(Date date); static int month(Date date); static int day(Date date); static int getTimeNumber(Date date, int i); static int week(Date date); static int getQuarter(Date date); static int dayOfQuarter(Date date); static int days(Date date); static int dayOfYear(Date date); static String dateRedMonthBegin(Date date, int n); static String dateRedMonthEnd(Date date, int n); static Date getDateByCalendar(Date date, int i, int j); static long getBetweenDiff(Date startDate, Date endDate, long time); static boolean isDBDefaultDate(Date date); }
DateUtil { public static String dateRedMonthEnd(Date date, int n) { String str = ""; int year = year(date); int month = month(date); if (n >= 12) { int m = n % 12; int s = n / 12; month = 12 - m + month; year = year - s; } else { month = month - n; } if (month == 0) { year = year - 1; month = 12; } if (month < 10) { str = "0" + month; } else { str = month + ""; } return year + "-" + str + "-" + maxDayOfMonth(year, month); }  static DateFormat getDateFormat(String format); static String format(String format, Date date); static Date parse(String format, String date); static String getDateStr(Date date, String format, int i, int j); static boolean isLeapYear(int year); static int maxDayOfMonth(int year, int month); static int year(Date date); static int month(Date date); static int day(Date date); static int getTimeNumber(Date date, int i); static int week(Date date); static int getQuarter(Date date); static int dayOfQuarter(Date date); static int days(Date date); static int dayOfYear(Date date); static String dateRedMonthBegin(Date date, int n); static String dateRedMonthEnd(Date date, int n); static Date getDateByCalendar(Date date, int i, int j); static long getBetweenDiff(Date startDate, Date endDate, long time); static boolean isDBDefaultDate(Date date); static final String YYYYMMDD; static final String YYYY_MM_DD; static final String DDMMYY; static final String YYYY_MM; static final String YYYY_MM_DD_HH_MM_SS; static final String YYMMDDHHMMSS; static final String YYYYMMDDHH; static final String YYYYMMDDHHMMSS; static final String HH_MM_SS; static final String HHMMSS; static final String HH_MM; static final long SECOND_TIME; static final long MINUTE_TIME; static final long HOUR_TIME; static final long DAY_TIME; }