zoukankan      html  css  js  c++  java
  • int类型转换成String , 不足n位 在前面补0

    1.String.format("%02d", 5);-->结果:05

    0代表前面要补的字符

    2代表字符串长度

    d表示参数为整数类型

    2.秒转换成时分秒

     1 private String secToTime(int time){
     2         String timeStr = null;  
     3         int hour = 0;  
     4         int minute = 0;  
     5         int second = 0;  
     6         if (time <= 0)  
     7             return "00:00";  
     8         else {  
     9             minute = time / 60;  
    10             if (minute < 60) {  
    11                 second = time % 60;  
    12                 timeStr = String.format("%02d", minute) + ":" + String.format("%02d", second);  
    13             } else {  
    14                 hour = minute / 60;  
    15                 if (hour > 99)  
    16                     return "99:59:59";  
    17                 minute = minute % 60;  
    18                 second = time - hour * 3600 - minute * 60;  
    19                 timeStr = String.format("%02d", hour) + ":" + String.format("%02d", minute) + ":" + String.format("%02d", second);  
    20             }  
    21         }  
    22         return timeStr;  
    23     }  
  • 相关阅读:
    MD5算法MFC实现
    asp.net2.0新特点
    file format
    C专家编程第二章学习笔记
    Bye Czech golden generation
    中间层
    学完谭C之后
    C语言学习之路
    荀子劝学篇
    C语言常用转义字符表
  • 原文地址:https://www.cnblogs.com/kelina2mark/p/4894793.html
Copyright © 2011-2022 走看看