敏捷工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
990 B

2 years ago
  1. package com.whn.hellospring.utils;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. public class DateUtils {
  6. /**
  7. * 计算两个日期之间相差的天数
  8. *
  9. * @param smdate 较小的时间
  10. * @param bdate 较大的时间
  11. * @return 相差天数
  12. */
  13. public static int daysBetween(Date smdate, Date bdate) {
  14. try {
  15. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  16. smdate = sdf.parse(sdf.format(smdate));
  17. bdate = sdf.parse(sdf.format(bdate));
  18. Calendar cal = Calendar.getInstance();
  19. cal.setTime(smdate);
  20. long time1 = cal.getTimeInMillis();
  21. cal.setTime(bdate);
  22. long time2 = cal.getTimeInMillis();
  23. long between_days = (time2 - time1) / (1000 * 3600 * 24);
  24. return Integer.parseInt(String.valueOf(between_days));
  25. } catch (Exception e) {
  26. return -1;
  27. }
  28. }
  29. }