aeolian

将seconds转为hh:mm:ss

    /**
     * 秒转hh:mm:ss格式
     * @param secString 秒字符串
     * @return hh小时mm分ss秒
     * String
     */
    public static String secondsToFormat(String secString){
        Integer seconds = Integer.parseInt(secString);
        Integer hour =0;
        Integer min =0;
        Integer second =0;
        String result ="";
        
        if (seconds>60) {   //是否大于零
            min = seconds/60;  //分钟
            second = seconds%60;  //
            if (min>60) {   //存在时
                hour=min/60;
                min=min%60;
            }
        }
        if (hour>0) {
            result=hour+"小时";
        }
        if (min>0) {
            result=result+min+"分";
        }else if (min==0&&hour>0) {  //当分为0时,但是时有值,所以要显示,避免出现2时0秒现象
            result=result+min+"分";
        }
        result=result+second+"秒";   //秒必须出现无论是否大于零
        System.out.println(result);
        return result;
    }

调用

    public static void main(String[] args) {
        secondsToFormat("7210");
    }

 

分类:

技术点:

相关文章:

  • 2021-09-17
  • 2021-09-17
  • 2021-12-26
  • 2021-11-19
  • 2021-09-17
  • 2021-09-17
  • 2021-12-18
  • 2021-11-01
猜你喜欢
  • 2021-09-17
  • 2021-09-17
  • 2021-09-17
  • 2021-09-17
  • 2021-09-17
  • 2021-12-31
  • 2021-09-17
相关资源
相似解决方案