美文网首页
毫秒数转换成天时分秒、时分秒

毫秒数转换成天时分秒、时分秒

作者: 恋君一生 | 来源:发表于2020-05-15 19:04 被阅读0次
    1、毫秒数转换成天时分秒
        /**
         * 毫秒数转换成天时分秒
         *
         * @param milliseconds
         */
        private void millisecondsConvertToDHMS(long milliseconds) {
            String daysStr;
            String hoursStr;
            String minutesStr;
            String secondsStr;
            //天
            long day = (milliseconds / 1000) / (24 * 3600);
            if (day < 10) {
                daysStr = "0" + day;
            } else {
                daysStr = day + "";
            }
            //时
            long hour = ((milliseconds / 1000) % (24 * 3600)) / 3600;
            if (hour < 10) {
                hoursStr = "0" + hour;
            } else {
                hoursStr = hour + "";
            }
            //分
            long minute = ((milliseconds / 1000) % 3600) / 60;
            if (minute < 10) {
                minutesStr = "0" + minute;
            } else {
                minutesStr = minute + "";
            }
            //秒
            long second = (milliseconds / 1000) % 60;
            if (second < 10) {
                secondsStr = "0" + second;
            } else {
                secondsStr = second + "";
            }
        }
    
    2、毫秒数转换成时分秒
        /**
         * 毫秒数转换成时分秒
         *
         * @param milliseconds
         */
        private void millisecondsConvertToHMS(long milliseconds) {
            String hoursStr;
            String minutesStr;
            String secondsStr;
    
            //时
            long hour = (milliseconds / 1000) / 3600;
            if (hour < 10) {
                hoursStr = "0" + hour;
            } else {
                hoursStr = hour + "";
            }
            //分
            long minute = ((milliseconds / 1000) % 3600) / 60;
            if (minute < 10) {
                minutesStr = "0" + minute;
            } else {
                minutesStr = minute + "";
            }
            //秒
            long second = (milliseconds / 1000) % 60;
            if (second < 10) {
                secondsStr = "0" + second;
            } else {
                secondsStr = second + "";
            }
        }
    

    相关文章

      网友评论

          本文标题:毫秒数转换成天时分秒、时分秒

          本文链接:https://www.haomeiwen.com/subject/lfdhohtx.html