将秒数转换成天具体的天时分秒
2016-07-11 11:04
246 查看
/** * 将秒数转换成天具体的天时分秒 * 比如172800S转换成2天0时0分0秒 * @param second * @return */ public String formatSecond(Object second){ String timeStr = "0秒"; if(second!=null){ Double s=(Double) second; String format; Object[] array; Integer days = (int)(s /(60 * 60 * 24)); Integer hours =(int)(s/(60*60) - days * 24); Integer minutes = (int)(s/60 - hours*60 - days * 24 * 60); Integer seconds = (int)(s-minutes*60-hours*60*60 - days * 24 * 60 * 60); if(days>0){ format="%1$,d天%2$,d时%3$,d分%4$,d秒"; array=new Object[]{days,hours,minutes,seconds}; } else if(hours>0){ format="%1$,d时%2$,d分%3$,d秒"; array=new Object[]{hours,minutes,seconds}; }else if(minutes>0){ format="%1$,d分%2$,d秒"; array=new Object[]{minutes,seconds}; }else{ format="%1$,d秒"; array=new Object[]{seconds}; } timeStr = String.format(format, array); } return timeStr ; }
相关文章推荐
- PHP 处理2038后的日期
- fragment切换
- HDU 1285 比赛排名(拓扑排序)
- Android SDK开发包国内下载地址
- DIV + CSS3 和 html5 + CSS3的区别
- 数据分析的一些思考
- Dubbo简单实例
- 操作系统内核为啥用C语言?(C语言特点)
- 文件
- 使用MR方案脚本访问HBase数据、Compact+Split问题-参数配置
- Safari地址栏搜索无效
- JavaScript 图片滚动(绝对酷)
- mysql主从复制Error1205
- MySQL有关ip地址的优化存储
- ios-IM
- Spring单元测试
- hadoop datanode 磁盘数据平衡
- VC高精度定时
- Xilinx FPGA电路配置
- drawable中android:shape的