我希望创建一个构造函数,将输入的秒数转换为HH:MM:SS格式。对于正数秒,我可以很容易地完成这个任务,但是对于负数秒,我遇到了一些困难。
以下是我目前的代码:
如果timeInSeconds是-1,我希望时间返回23:59:59等。谢谢!
以下是我目前的代码:
private final int HOUR, MINUTE, SECOND, TOTAL_TIME_IN_SECONDS;
public MyTime(int timeInSeconds) {
if (timeInSeconds < 0) {
//Convert negative seconds to HH:MM:SS
} else {
this.HOUR = (timeInSeconds / 3600) % 24;
this.MINUTE = (timeInSeconds % 3600) / 60;
this.SECOND = timeInSeconds % 60;
this.TOTAL_TIME_IN_SECONDS
= (this.HOUR * 3600)
+ (this.MINUTE * 60)
+ (this.SECOND);
}
}
如果timeInSeconds是-1,我希望时间返回23:59:59等。谢谢!