把秒或者毫秒转为小时分钟

/**
    *
    * @param millis  要转化的毫秒数。
    *         
    * @param isWhole  是否强制全部显示小时/分。
    *            
    * @param isFormat 时间数字是否要格式化,如果true:少位数前面补全;如果false:少位数前面不补全。
    *            
    * @return 返回时间字符串:小时/分/秒/毫秒的格式(如:24903600 --> 06小时55分钟)。
    */
   public static String millisToStringShort(long millis, boolean isWhole,
           boolean isFormat) {
       String h = "";
       String m = "";
       if (isWhole) {
           h = isFormat ? "00小时" : "0小时";
           m = isFormat ? "00分钟" : "0分钟";
       }

       long temp = millis;

       long hper = 60 * 60 * 1000;
       long mper = 60 * 1000;
       long sper = 1000;

       if (temp / hper > 0) {
           if (isFormat) {
               h = temp / hper < 10 ? "0" + temp / hper : temp / hper + "";
           } else {
               h = temp / hper + "";
           }
           h += "小时";
       }
       temp = temp % hper;

       if (temp / mper > 0) {
           if (isFormat) {
               m = temp / mper < 10 ? "0" + temp / mper : temp / mper + "";
           } else {
               m = temp / mper + "";
           }
           m += "分钟";
       }

       return h + m;
   }
/**
    *  把毫秒转为   分:秒
    */
   public static String millisToStringShort(long millis, boolean isWhole,
           boolean isFormat) {
       String h = "";
       String m = "";
       if (isWhole) {
           h = isFormat ? "00小时" : "0小时";
           m = isFormat ? "00分钟" : "0分钟";
       }

       long temp = millis;

//       long hper = 60 * 60 * 1000;
       long mper = 60 * 1000;
       long sper = 1000;

       if (temp / mper > 0) {
           if (isFormat) {
               h = temp / mper < 10 ? "0" + temp / mper : temp / mper + "";
           } else {
               h = temp / mper + "";
           }
           h += ":";
       }
       temp = temp % mper;

       if (temp / sper > 0) {
           if (isFormat) {
               m = temp / sper < 10 ? "0" + temp / sper : temp / sper + "";
           } else {
               m = temp / sper + "";
           }
           m += "";
       }

       return h + m;
   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值