当前位置:网站首页>将指定秒转为时分秒格式
将指定秒转为时分秒格式
2022-07-23 05:48:00 【枯枫叶】
1 工具方法
/** * 将秒转为时分秒格式【01:01:01】 * @param second 需要转化的秒数 * @return */
public static String secondConvertHourMinSecond(Long second) {
String str = "00:00:00";
if (second == null || second < 0) {
return str;
}
// 得到小时
long h = second / 3600;
str = h > 0 ? ((h < 10 ? ("0" + h) : h) + ":") : "00:";
// 得到分钟
long m = (second % 3600) / 60;
str += (m < 10 ? ("0" + m) : m) + ":";
//得到剩余秒
long s = second % 60;
str += (s < 10 ? ("0" + s) : s);
return str;
}
2 调用
public static void main(String[] args) {
System.out.println(secondConvertHourMinSecond(Long.valueOf(3661)));
}
3 结果
说明:如果不足一小时,也会返回小时,不足一分钟也会返回分钟,也就是说:最后的格式不管怎么样都是时分秒的格式
边栏推荐
猜你喜欢

TI单芯片毫米波雷达代码走读(二十五)—— 角度维(3D)处理流程

录入数学公式至mark down文档的方法

雷达导论PART VII.3 SAR图像的形成和处理

Ronge answer script production (latest in 2020)

Hcip --- OSPF details

雷达导论PART VII.4 SAR系统设计

Unity3d:assetbundle simulation loading, synchronous loading, asynchronous loading, dependent package loading, automatic labeling, AB browser, incremental packaging

雷达导论PART VII.2 成像方法

Simple use of psutil monitoring

秘钥远程登录服务器实现免密登录实战
随机推荐
4D天线阵列布局设计
问题解决:Script file ‘Scripts\pip-script.py‘ is not present.
RHCSA--文件內容瀏覽、cut、uniq、sort、.tr命令使用
Ronge answer script production (latest in 2020)
C#输入一个字母,判断其大小写
Unity3d HD rendering pipeline cannot play video on the model
nfs服务部署笔记
用户与组的管理、文件的权限
0 array leetcode605. Flower planting problem
OSPF multi area configuration instance learning record
C # enter a letter and judge its case
helm安装rancher
Unity3d+gameframework: resource analysis, resource dependency, circular dependency detection
Pod 拓扑约束
2020-10-16
HCIA----02
SFTP deployment configuration
ZABBIX monitoring detailed installation to deployment
使用vscode进行远程编辑和调试
Three layer switching configuration example learning record