【Java开发基础】计算两个毫秒之间相差多少天

 

    private long daysBeforeExpire() {
        return daysBetween(System.currentTimeMillis(), getExpireDate().getTime());
    }

    private long daysAfterProduce() {
        return daysBetween(getProducedDate().getTime(), System.currentTimeMillis());
    }


    public static long daysBetween(long from, long to) {
        long gap = to - from;
        if (gap < 0) {
            return -1;
        }
        return gap / (24 * 3600 * 1000);
    }

  

posted @ 2022-07-27 12:42  垄上行  阅读(154)  评论(0编辑  收藏  举报