1. /**
    2. * 计算出两个时间的间隔
    3. * @param startDate 起始时间
    4. * @param endDate 结束时间
    5. */
    6. public class DateUtils {
    7. public static String getDatePoor(Date startDate, Date endDate) {
    8. long nd = 1000 * 24 * 60 * 60;
    9. long nh = 1000 * 60 * 60;
    10. long nm = 1000 * 60;
    11. long ns = 1000;
    12. // 获得两个时间的毫秒时间差异
    13. long diff = endDate.getTime() - startDate.getTime();
    14. // 计算差多少天
    15. long day = diff / nd;
    16. // 计算差多少小时
    17. long hour = diff % nd / nh;
    18. // 计算差多少分钟
    19. long min = diff % nd % nh / nm;
    20. // 计算差多少秒
    21. long sec = diff % nd % nh % nm / ns;
    22. return day + "天" + hour + "小时" + min + "分钟" + sec + "秒";
    23. }
    24. }