zoukankan      html  css  js  c++  java
  • 秒转为时分秒格式

    将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");
        }

  • 相关阅读:
    offset家族
    $的符号封装
    操作字符串
    无缝滚动
    根据字符返回位置
    网页编码和解码
    小米手机案例
    字符串对象常用方法
    匀速运动案例
    Render Functions & JSX
  • 原文地址:https://www.cnblogs.com/aeolian/p/9187410.html
Copyright © 2011-2022 走看看