秒转为日时分秒(00:00:00:00格式)

日志记录job执行耗时, 格式为00:00:00:00, 例如:00:23:15:00, 代表执行了23小时15分钟.

工具类写了个方法:

/**
 * @Author: liangyadong
 * @Date: 2019/3/21 0021 下午 2:33
 * @Description: 返回日时分秒 格式:days:HI24:mm:ss 小时为24小时制
 */
public static String secondToTime(long seconds) {
    long days = seconds / 86400;//转换天数
    seconds = seconds % 86400;//剩余秒数
    long hours = seconds / 3600;//转换小时数
    seconds = seconds % 3600;//剩余秒数
    long minutes = seconds / 60;//转换分钟
    seconds = seconds % 60;//剩余秒数

    String day = "";
    String hour = "";
    String minute = "";
    String second = "";
    day = day.format("%02d", days);
    hour = hour.format("%02d", hours);
    minute = minute.format("%02d", minutes);
    second = second.format("%02d", seconds);

    String ddHHmmss = day + ":" + hour + ":" + minute + ":" + second;

    return ddHHmmss;

}

效果:

 

感谢:

  https://blog.csdn.net/github_38765507/article/details/80663430

  https://blog.csdn.net/tongchen1231/article/details/18564883

 

posted @ 2019-03-21 15:30  习惯沉淀  阅读(1447)  评论(0编辑  收藏  举报