37 lines
923 B
Java
37 lines
923 B
Java
|
public class MyDate {
|
||
|
private int year;
|
||
|
private int month;
|
||
|
private int day;
|
||
|
|
||
|
private int[] monthDurations = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||
|
|
||
|
public String toString() {
|
||
|
return String.format("%04d-%02d-%02d", year, month, day);
|
||
|
}
|
||
|
|
||
|
public MyDate tomorrow() {
|
||
|
MyDate newDate = new MyDate(this.year, this.month, this.day+1);
|
||
|
|
||
|
if (newDate.day > monthDurations[newDate.month-1]) {
|
||
|
newDate.day = 1;
|
||
|
newDate.month += 1;
|
||
|
}
|
||
|
|
||
|
if (newDate.month > 12) {
|
||
|
newDate.month = 1;
|
||
|
newDate.year += 1;
|
||
|
}
|
||
|
|
||
|
return newDate;
|
||
|
}
|
||
|
|
||
|
public boolean isEqual(MyDate date) {
|
||
|
return (this.year == date.year && this.month == date.month && this.day == date.day);
|
||
|
}
|
||
|
|
||
|
public MyDate(int y, int m, int d) {
|
||
|
this.year = y;
|
||
|
this.month = m;
|
||
|
this.day = d;
|
||
|
}
|
||
|
}
|