加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
MyTime.java 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
x曦月y 提交于 2016-07-20 10:45 . work
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());
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化