I'm learning the Calendar class in Java and I am unable to understand the Set(Calendar.Day OF MONTH)
method.
Here it goes:
import java.util.Calendar;
import java.util.Date
public class TestCalender
{
public static void main(String[] args)
{
Calendar cal = Calendar.getInstance();
Date date= cal.getTime();
System.out.println(date);
cal.set(Calendar.DAY_OF_MONTH,33);
//cal.set(Calendar.MONTH,13);------>(1)
Date newdate = cal.getTime();
System.out.println(newdate);
Output:
Fri May 12 17:30:50 CDT 2017
Fri Jun 02 17:30:50 CDT 2017
When I uncomment the statement(1) the output changes to:
Fri May 12 17:33:22 CDT 2017
Mon Mar 05 17:33:22 CST 2018
Here is my question:
I understood the change of Month to March but I'm not able to figure out why the date has changed to 5. As per my understanding shouldn't the date be changed to April 02 2018 (when 33 days of March is being computed since March has only 31 days the count moves to the month of April).
I will be extremely grateful if someone could help in clearing this doubt.
Thanks in advance.
Regards Roopa