android通过秒换算成时分秒
2016-02-18 11:36
507 查看
<p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"></span></p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;">//把秒转换成时分秒</p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;"><span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">public static String cal(int second) {</span></p> int h = 0; int d = 0; int s = 0; int temp = second % 3600; if (second > 3600) { h = second / 3600; if (temp != 0) { if (temp > 60) { d = temp / 60; if (temp % 60 != 0) { s = temp % 60; } } else { s = temp; } } } else { d = second / 60; if (second % 60 != 0) { s = second % 60; } } return h + "时" + d + "分" + s + "秒"; }
通过秒分别得出多少小时多少分多少秒
public class TimeUtils {
public static String getHours(long second) {//计算秒有多少小时
long h = 00;
if (second > 3600) {
h = second / 3600;
}
return h+"";
}
public static String getMins(long second) {//计算秒有多少分
long d = 00;
long temp = second % 3600;
if (second > 3600) {
if (temp != 0) {
if (temp > 60) {
d = temp / 60;
}
}
} else {
d = second / 60;
}
return d + "";
}
public static String getSeconds(long second) {//计算秒有多少秒
long s = 0;
long temp = second % 3600;
if (second > 3600) {
if (temp != 0) {
if (temp > 60) {
if (temp % 60 != 0) {
s = temp % 60;
}
} else {
s = temp;
}
}
} else {
if (second % 60 != 0) {
s = second % 60;
}
}
return s + "";
}
}
相关文章推荐
- 一个SharedPreferences的抽离类
- Android工具包AndroidUtils
- 【常用工具类】NetUtil(检测当前网络状态)
- Android开源项目第二篇——工具库篇
- Android常用工具库
- SharedPreference的封装
- Android开发用到的工具
- Android常用工具类
- Android快速开发系列 10个常用工具类
- Android工具类,你能想到的都在这里
- 20170303 每日一个工具类:Drawable转Bitmap
- Android---工具类
- Android常用工具类...
- Android 工具类总:
- Android开发常用工具类AndroidUtilCode
- 文件大小转换工具Formatter.formatFileSize(MainActivity.this, bitmap.getByteCount())
- Android开发常用工具类
- Android 如何查看apk安装包的AndroidManifest.xml文件
- Android设置TextView显示指定个数字符,超过部分显示...(省略号)的方法
- 修改android 开机动画