查漏补缺之ParamsUtils(把时间转换成字符串)

以下为时间转换成字符串的工具类,可直接引用:

public class ParamsUtils {
    public final static int INVALID = -1;
    public static int getInt(String str){
        int num = INVALID;
        try {
            num = Integer.parseInt(str);
        } catch (NumberFormatException e) {
        }
        return num;
    }
    public static String millsecondsToStr(int seconds){ //把时间转换成字符串
        seconds = seconds / 1000;
        String result = "";
        int hour = 0, min = 0, second = 0;
        hour = seconds / 3600;
        min = (seconds - hour * 3600) / 60;
        second = seconds - hour * 3600 - min * 60;
        if (hour < 10) {
            result += "0" + hour + ":";
        } else {
            result += hour + ":";
        }
        if (min < 10) {
            result += "0" + min + ":";
        } else {
            result += min + ":";
        }
        if (second < 10) {
            result += "0" + second;
        } else {
            result += second;
        }
        return result;
    }
    public static int dpToPx(Context context, int height){ //dp转换成px
        float density = context.getResources().getDisplayMetrics().density;
        height = (int) (height * density + 0.5f);
        return height;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值