栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

部分单位转换工具类

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

部分单位转换工具类

字节b转kb/mb/gb
private static final int rateB = 1024;
public static String getPrintSize(long size) {
    if (size < rateB) {
        return size + "B";
    }
    //kb
    long temp = size / rateB;
    if (temp < 1024) {
        return temp + "KB";
    }
    //mb
    size = temp;
    temp = size / rateB;
    DecimalFormat df = new DecimalFormat("0.0");
    if (temp < 1024) {
        return df.format(size / (float) rateB) + "MB";
    }
    return df.format(temp / (float) rateB) + "GB";
}
时间秒转xx:xx格式时长
private static final int rateM = 60;
public static String getTimeShow(String duration) {
    double d = Double.parseDouble(duration);
    //时间整数秒
    int i = (int) d;
    if (i < rateM) {
        return "00:" + (i < 10 ? "0" + i : i);
    }

    //分
    int temp = i / rateM;
    int second = i % rateM;
    String s = second < 10 ? "0" + second : second + "";

    if (temp < 60) {
        return (temp < 10 ? "0" + temp : temp) + ":" + s;
    }

    //时
    int hour = temp / rateM;
    int minutes = temp % rateM;
    String m = minutes < 10 ? "0" + minutes : minutes + "";
    return (hour < 10 ? "0" + hour : hour) + ":" + m + ":" + s;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/287522.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号