代码拉取完成,页面将自动刷新
import java.text.DecimalFormat;
public class MyTime {
private int hour=0;
private int minute=0;
private int second=0;
public MyTime(){
}
public MyTime(int hour,int minute,int second){
this.hour=hour;
this.minute=minute;
this.second=second;
}
public void setTime(int hour,int minute,int second){
this.hour=hour;
this.minute=minute;
this.second=second;
}
public int getHour(){
return hour;
}
public int getMinute(){
return minute;
}
public int getSecond(){
return second;
}
public void setHour(int hour){
this.hour=hour;
}
public void setSecond(int second){
this.second=second;
}
public void setMinute(int minute){
this.minute=minute;
}
public String toString(){
DecimalFormat df = new DecimalFormat("##00");
return df.format(hour)+":"+df.format(minute)+":"+df.format(second);
}
public MyTime nextSecond(){
this.second++;
if(this.second==60){
this.minute++;
this.second=0;
}
if(minute==60){
minute=0;
hour++;
}
if(hour==24){
hour=0;
}
return this;
}
public MyTime nextMinute(){
this.minute++;
if(minute==60){
hour++;
minute=0;
}if(hour==24){
hour=0;
}
return this;
}
public MyTime nextHour(){
hour++;
if(hour==24){
hour=0;
}
return this;
}
public MyTime previousSecond(){
second--;
if(second==-1){//当second==0;- 1==-1就赋值;就完成了循环样式,只执行一次。1-59.
second=59;
minute--;
}
if(minute==-1){
minute=59;
hour--;
}
if(hour==23){
hour=23;
}
return this;
}
public MyTime previousMinute(){
minute--;
if(minute==59){
minute=59;
hour--;
}
if(hour==23){
hour=23;
}
return this;
}
public MyTime previousHour(){
hour--;
if(hour==23){
hour=23;
}
return this;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyTime my = new MyTime(23,59,0);
System.out.println(my.previousSecond());
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。