@Test public void testSubDay() { System.out.println(DateUtil.subDay("2015-01-05 13:00:00", "2015-01-05 13:00:00")); System.out.println(DateUtil.subDay("2015-01-05 13:00:00", "2015-01-06 10:00:00")); System.out.println(DateUtil.subDay("2015-01-05 13:00:00", "2015-03-05 13:00:00")); System.out.println(DateUtil.subDay("2015-01-05 13:00:00", "2015-01-07 13:00:00")); System.out.println(DateUtil.subDay("2015-01-05 13:00:00", "2015-01-08 13:00:00")); }
public static int subDay(Date startTime, Date endTime) { int days = 0; Calendar can1 = Calendar.getInstance(); can1.setTime(startTime); Calendar can2 = Calendar.getInstance(); can2.setTime(endTime); int year1 = can1.get(Calendar.YEAR); int year2 = can2.get(Calendar.YEAR); Calendar can = null; if (can1.before(can2)) { days -= can1.get(Calendar.DAY_OF_YEAR); days += can2.get(Calendar.DAY_OF_YEAR); can = can1; } else { days -= can2.get(Calendar.DAY_OF_YEAR); days += can1.get(Calendar.DAY_OF_YEAR); can = can2; } for (int i = 0; i < Math.abs(year2 - year1); i++) { days += can.getActualMaximum(Calendar.DAY_OF_YEAR); can.add(Calendar.YEAR, 1); } return days; }
DateUtil { public static int subDay(Date startTime, Date endTime) { int days = 0; Calendar can1 = Calendar.getInstance(); can1.setTime(startTime); Calendar can2 = Calendar.getInstance(); can2.setTime(endTime); int year1 = can1.get(Calendar.YEAR); int year2 = can2.get(Calendar.YEAR); Calendar can = null; if (can1.before(can2)) { days -= can1.get(Calendar.DAY_OF_YEAR); days += can2.get(Calendar.DAY_OF_YEAR); can = can1; } else { days -= can2.get(Calendar.DAY_OF_YEAR); days += can1.get(Calendar.DAY_OF_YEAR); can = can2; } for (int i = 0; i < Math.abs(year2 - year1); i++) { days += can.getActualMaximum(Calendar.DAY_OF_YEAR); can.add(Calendar.YEAR, 1); } return days; } }
DateUtil { public static int subDay(Date startTime, Date endTime) { int days = 0; Calendar can1 = Calendar.getInstance(); can1.setTime(startTime); Calendar can2 = Calendar.getInstance(); can2.setTime(endTime); int year1 = can1.get(Calendar.YEAR); int year2 = can2.get(Calendar.YEAR); Calendar can = null; if (can1.before(can2)) { days -= can1.get(Calendar.DAY_OF_YEAR); days += can2.get(Calendar.DAY_OF_YEAR); can = can1; } else { days -= can2.get(Calendar.DAY_OF_YEAR); days += can1.get(Calendar.DAY_OF_YEAR); can = can2; } for (int i = 0; i < Math.abs(year2 - year1); i++) { days += can.getActualMaximum(Calendar.DAY_OF_YEAR); can.add(Calendar.YEAR, 1); } return days; }  }
DateUtil { public static int subDay(Date startTime, Date endTime) { int days = 0; Calendar can1 = Calendar.getInstance(); can1.setTime(startTime); Calendar can2 = Calendar.getInstance(); can2.setTime(endTime); int year1 = can1.get(Calendar.YEAR); int year2 = can2.get(Calendar.YEAR); Calendar can = null; if (can1.before(can2)) { days -= can1.get(Calendar.DAY_OF_YEAR); days += can2.get(Calendar.DAY_OF_YEAR); can = can1; } else { days -= can2.get(Calendar.DAY_OF_YEAR); days += can1.get(Calendar.DAY_OF_YEAR); can = can2; } for (int i = 0; i < Math.abs(year2 - year1); i++) { days += can.getActualMaximum(Calendar.DAY_OF_YEAR); can.add(Calendar.YEAR, 1); } return days; }  static String currentDateTime(); static String dateTime(Date date); static Date dateTime(String datestr); static String currentDate(); static String date(Date date); static Date date(String dateStr); static String currentTime(); static String time(Date date); static Date time(String dateStr); static Date year(int year); static Date year(Date date, int year); static Date month(int month); static Date month(Date date, int month); static Date day(int day); static Date day(Date date, int day); static Date hour(float hour); static Date hour(Date date, float hour); static Date minute(int minute); static Date minute(Date date, int minute); static boolean isDate(String date); static long subtract(Date date1, Date date2); static long subtract(String date1, String date2); static int subtractMinute(String date1, String date2); static int subtractMinute(Date date1, Date date2); static int subtractHour(Date date1, Date date2); static int subtractHour(String date1, String date2); static int subtractDay(String date1, String date2); static int subtractDay(Date date1, Date date2); static int subtractMonth(String date1, String date2); static int subtractMonth(Date date1, Date date2); static int subtractYear(String date1, String date2); static int subtractYear(Date date1, Date date2); static String subtractTime(String date1, String date2); static String subtractDate(String date1, String date2); static int subDay(Date startTime, Date endTime); static int subDay(String startTime, String endTime); static long subtimeBurst(String startDate, String endDate, String timeBurst); static long subtimeBurst(Date startDate, Date endDate, String timeBurst); static Date calculate(String date, int second, String timeBurst); static Date calculate(Date date, int second, String timeBurst); static boolean between(String startTime, String endTime, Date date); static boolean between(Date startTime, Date endTime, Date date); }
DateUtil { public static int subDay(Date startTime, Date endTime) { int days = 0; Calendar can1 = Calendar.getInstance(); can1.setTime(startTime); Calendar can2 = Calendar.getInstance(); can2.setTime(endTime); int year1 = can1.get(Calendar.YEAR); int year2 = can2.get(Calendar.YEAR); Calendar can = null; if (can1.before(can2)) { days -= can1.get(Calendar.DAY_OF_YEAR); days += can2.get(Calendar.DAY_OF_YEAR); can = can1; } else { days -= can2.get(Calendar.DAY_OF_YEAR); days += can1.get(Calendar.DAY_OF_YEAR); can = can2; } for (int i = 0; i < Math.abs(year2 - year1); i++) { days += can.getActualMaximum(Calendar.DAY_OF_YEAR); can.add(Calendar.YEAR, 1); } return days; }  static String currentDateTime(); static String dateTime(Date date); static Date dateTime(String datestr); static String currentDate(); static String date(Date date); static Date date(String dateStr); static String currentTime(); static String time(Date date); static Date time(String dateStr); static Date year(int year); static Date year(Date date, int year); static Date month(int month); static Date month(Date date, int month); static Date day(int day); static Date day(Date date, int day); static Date hour(float hour); static Date hour(Date date, float hour); static Date minute(int minute); static Date minute(Date date, int minute); static boolean isDate(String date); static long subtract(Date date1, Date date2); static long subtract(String date1, String date2); static int subtractMinute(String date1, String date2); static int subtractMinute(Date date1, Date date2); static int subtractHour(Date date1, Date date2); static int subtractHour(String date1, String date2); static int subtractDay(String date1, String date2); static int subtractDay(Date date1, Date date2); static int subtractMonth(String date1, String date2); static int subtractMonth(Date date1, Date date2); static int subtractYear(String date1, String date2); static int subtractYear(Date date1, Date date2); static String subtractTime(String date1, String date2); static String subtractDate(String date1, String date2); static int subDay(Date startTime, Date endTime); static int subDay(String startTime, String endTime); static long subtimeBurst(String startDate, String endDate, String timeBurst); static long subtimeBurst(Date startDate, Date endDate, String timeBurst); static Date calculate(String date, int second, String timeBurst); static Date calculate(Date date, int second, String timeBurst); static boolean between(String startTime, String endTime, Date date); static boolean between(Date startTime, Date endTime, Date date);  }