我想在给定日期(月日年)之后显示明天的日期 我没有编程经验,但我正在尝试习惯这样做。我对此进行了编码,但它甚至无法正常工作,而且我一直坚持下去。谁能看一下?
int Year, Month, Day;
int tYear, tMonth, tDay;
System.out.print("Enter the month [1 to 12]: ");
System.out.print("Enter the day of the month [1 to 31]: ");
System.out.print("Enter the year: ");
tDay = Day + 1;
tMonth = Month;
tYear = Year;
if (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) {
if (tDay > 31) {
tMonth = Month + 1;
tDay = 1;
}
} else if (Month == 4 || Month == 6 || Month == 9 || Month == 11) {
if (tDay > 30) {
tMonth = Month + 1;
tDay = 1;
}
} else {
if ((Year % 4 == 0) && (!(Year % 100 == 0) || (Year % 400) == 0)) {
if (tDay > 29) {
tMonth = 3;
tDay = 1;
}
} else {
if (tDay > 28) {
tMonth = 3;
tDay = 1;
}
}
}
if (tMonth == 13) {
tMonth = 1;
tYear = Year + 1;
}
System.out.println("Today's date is: " + Month +
"/" + Day + "/" + Year + ".");
System.out.println("Tomorrow's date will be: " + tMonth +
"/" + tDay + "/" + tYear + ".");
最佳答案
我会使用 JodaTime对于这一切。有一个plusDays在那里发挥作用
DateTime dt = new DateTime(2015,9,20, 0, 0);
DateTime oneDayLater = dt.plusDays(1);
有一个日期时间ctor这允许您自 1970 年以来以毫秒为单位传递,这将使您可以轻松地使用 java 的 Calendar 和 Date 类。
关于java - 我想在给定日期之后显示明天的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33340644/