I’m trying to set a calendar value to it’s base (0) to compare it to another value later on. When I tried to print the result I’m getting the month value when using SimpareDateFormat. Any thoughts? and I’m doing it right?
SimpleDateFormat DataDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat DataDateFormatMonth = new SimpleDateFormat("MM");
Calendar cld = Calendar.getInstance();
cld.set(1, 1, 1);
System.out.println(DataDateFormat.format(cld.getTime())); // -> 0001-02-01
System.out.println(DataDateFormatMonth.format(cld.getTime())); // -> 02 !!!!
System.out.println(cld.get(Calendar.MONTH)); // -> 1
Month interval is 0 to 11 in Calendar API.
Calendar.MONTH will return an int value (2) which in your case is the value of MM . i.e., Calander.MONTH is a constant
breaking down:
For instance change your last print statement to
the output will be 10(it will return the month value in the format) as Calendar.YEAR would return 1.