Java 秒转换为时分秒:代码示例和用法
以下是将秒转换为时分秒的Java代码示例:
public static String formatDuration(int seconds) {
int h = seconds / 3600;
int m = (seconds % 3600) / 60;
int s = seconds % 60;
return String.format('%02d:%02d:%02d', h, m, s);
}
使用示例:
int seconds = 3661; // 1 hour, 1 minute, 1 second
String duration = formatDuration(seconds);
System.out.println(duration); // output: 01:01:01
AI 优化版
原文地址:https://www.cveoy.top/t/topic/mWZ0 著作权归作者所有。请勿转载和采集!