查漏補缺之ParamsUtils(把時間轉換成字串)
摘要:
以下為時間轉換成字串
的工具類,可直接引用:
public class ParamsUtils {
public final static int INVALID = -1;
public static int getInt(String st...
以下為時間轉換成字串 的工具類,可直接引用:
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; } }