-2
obj.setDate(5,25,00);
    
public void setDate(int month, int date1, int year) {
    cal.set(Calendar.MONTH,--month);
    cal.set(Calendar.DATE, date1);
    cal.set(Calendar.YEAR, year);
}

When I try to run the code, the year is being upgrade to show as 01, and not showing as 00 as it should. Same problem with "month" but I did --. Can someone point out what is happening here? Thank you.

pcsutar
  • 1,715
  • 2
  • 9
  • 14
GoGo001
  • 1
  • 2
  • 2
    You are using terrible date-time classes that are now legacy, supplanted years ago by the *java.time* classes defined in JSR 310. Use `LocalDate.of( 2000 , Month.MAY , 25 )` – Basil Bourque Sep 07 '21 at 03:37
  • 2
    Regarding `00`… Preceding a numeric literal with a zero in Java indicates an octal number rather than a decimal number. – Basil Bourque Sep 07 '21 at 03:41
  • 1
    A [mre], please? Also asking because what you say sounds weird. And @BasilBourque is right, `Calendar` is poorly designed and long outdated. Instead use `LocalDate` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Sep 07 '21 at 05:50

1 Answers1

0

Month value is 0-based, i.e. 0 for January so this is expected.

And what do you mean by year 00? There is no "zero" year in Gregorian calendar, before year 1 AD there was year 1 BC. If you mean 1900 or 2000 you should use just that obj.setDate(5, 25, 2000).

See also: Year 0000 in java

pawel
  • 513
  • 8
  • 15
  • Thank you, it was part of my homework to write methods with those given main method., such as `obj.setDate(5,25,00);` – GoGo001 Sep 07 '21 at 03:45