• 格式化时间(xx天xx时xx分xx秒)


    /**
    * 格式化时间(xx天xx时xx分xx秒)
    * @param mills
    * @return
    */
    public static String formatTime(long ms) {
      if (ms == 0) {
        return "";
      }
      Integer ss = 1000;
      Integer mi = ss * 60;
      Integer hh = mi * 60;
      Integer dd = hh * 24;

      long day = ms / dd;
      long hour = (ms - day * dd) / hh;
      long minute = (ms - day * dd - hour * hh) / mi;
      long seconds = (ms - day * dd - hour * hh - minute * mi) / ss;

      StringBuilder sb = new StringBuilder();
      if (day > 0) {
        sb.append(day + "天" + hour + "时" + minute + "分" + seconds + "秒");
      } else if (hour > 0) {
        sb.append(hour + "时" + minute + "分" + seconds + "秒");
      } else if (minute > 0) {
        sb.append(minute + "分" + seconds + "秒");
      } else if (seconds > 0) {
        sb.append(seconds + "秒");
      }
      return sb.toString();
    }

  • 相关阅读:
    路飞学城Python-Day142
    路飞学城Python-Day141
    路飞学城Python-Day140
    路飞学城Python-Day136
    路飞学城Python-Day137
    路飞学城Python-Day117
    java基础知识总结
    Maven
    MySql实现分页查询
    js中的正则表达式入门
  • 原文地址:https://www.cnblogs.com/baimj/p/14095647.html
Copyright © 2020-2023  润新知