获取过去某个时间到现在相差的时间天时分

 private String getTimeOutStr(long nowDate, long lastTime) {
        String str ="";
        long minute = 1000 * 60 ;
        long hour = 1000 * 60 * 60 ;
        long day = 1000 * 60 * 60 *  24;
        long time = nowDate - lastTime;
        if(time/day >0){
            long dayNum = time / day;
            str += dayNum + "天";
            long hourTime = time % day;
            if(hourTime/hour > 0){
                long hourNum = hourTime / hour;
                str += hourNum + "小时";
                long minuteTime = hourTime % hour;
                if(minuteTime/minute > 0){
                    long minuteNum = minuteTime / minute;
                    str += minuteNum + "分钟";
                }
            }
        }else {
            if(time/hour > 0){
                long hourNum = time / hour;
                str += hourNum + "小时";
                long minuteTime = time % hour;
                if(minuteTime/minute > 0){
                    long minuteNum = minuteTime / minute;
                    str += minuteNum + "分钟";
                }
            }else {
                long minuteNum = time / minute;
                str += minuteNum + "分钟";
            }
        }
        return str;
    }

 

posted @ 2023-11-10 16:51  我没有出家  阅读(9)  评论(0编辑  收藏  举报