考虑一天的时间,以秒为单位,将其转换为hhmmss格式的时间。请注意,时间已经过了中午,因此小时数永远不会少于12小时。
示例输入#1 (86399)
示例输出#1 235959
MyApproach:
我想问一下如何转换时间
以秒为单位给出时间 86399
根据我的理解,我这次转换了
($86399$/$3600$)=23 hrs
($86399$/$60$)=1439minutes
$86399$=$87861$seconds
我认为我做错了,我不知道为什么? 任何人都可以指导如何转换这段时间吗?
@Edit
以下是我的代码:
public class SecondsToTime
{
public static void main(String args[])
{
SecondsToTime obj = new SecondsToTime();
int result = obj.toTime(86399);
System.out.println(result);
}
public int toTime(int seconds)
{
int a=n/$3600$=23 hrs //if n=86399
int b=n/$60$=1439minutes //if n=86399
int c=n=$87861$seconds //if n=86399
return a+b+c;
}
}
答案 0 :(得分:2)
你迈出了第一步,你只是错过了第二步。要获得超过一小时的分钟数:
(input / 60) % 60
换句话说:
(timeOfDayInSeconds / secondsPerMinute) % minutesPerHour