比较两个日期时间差

来源:互联网 发布:淘宝商品怎么分类 编辑:程序博客网 时间:2024/05/17 01:37

SQL
分钟差

round((UNIX_TIMESTAMP(date1)-UNIX_TIMESTAMP(date2))/60)>?  

java

public static long getDateMinutesDiff(Date endDate, Date nowDate) {        long nd = 1000 * 24 * 60 * 60;        long nh = 1000 * 60 * 60;        long nm = 1000 * 60;        // long ns = 1000;        // 获得两个时间的毫秒时间差异        long diff = endDate.getTime() - nowDate.getTime();        // 计算差多少分钟        long min = diff % nd % nh / nm;        // 计算差多少秒//输出结果        // long sec = diff % nd % nh % nm / ns;        return min;    }