一段求时间的JAVA源码,求大家帮我看看出了什么问题。
一下是我参考教材写的一个类的源代码。publicclassComputeTime{privatelongtime;privateintsecond;privateinth...
一下是我参考教材写的一个类的源代码。
public class ComputeTime {
private long time;
private int second;
private int hour;
private int minute;
ComputeTime(long timeInput){
this.time = timeInput;
}
public void compute(){
long totalMilliSeconds = this.time;
long totalSeconds = totalMilliSeconds / 1000;
long currentSecond = totalSeconds %60;
long totalMinutes = totalSeconds / 60;
long currentMinute = totalMinutes % 60;
long totalHours = totalMinutes / 60;
long currentHour = totalHours % 24;
this.hour = (int)currentHour;
this.minute = (int)currentMinute;
this.second = (int)currentSecond;
}//这里可能冗余了,不再改了。
public void printTime(){
System.out.println("It's now " + hour + ":" + minute + ":" + second + " GMT.");
}
}
我用UNIX时间戳作为构造方法的实参,但是总是无法得到正确的时间。求大佬帮忙答疑解惑,万分感谢。
这个代码是利用UNIX时间戳求现在时刻的 展开
public class ComputeTime {
private long time;
private int second;
private int hour;
private int minute;
ComputeTime(long timeInput){
this.time = timeInput;
}
public void compute(){
long totalMilliSeconds = this.time;
long totalSeconds = totalMilliSeconds / 1000;
long currentSecond = totalSeconds %60;
long totalMinutes = totalSeconds / 60;
long currentMinute = totalMinutes % 60;
long totalHours = totalMinutes / 60;
long currentHour = totalHours % 24;
this.hour = (int)currentHour;
this.minute = (int)currentMinute;
this.second = (int)currentSecond;
}//这里可能冗余了,不再改了。
public void printTime(){
System.out.println("It's now " + hour + ":" + minute + ":" + second + " GMT.");
}
}
我用UNIX时间戳作为构造方法的实参,但是总是无法得到正确的时间。求大佬帮忙答疑解惑,万分感谢。
这个代码是利用UNIX时间戳求现在时刻的 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询