[JAVA] Calendar.MONTH

It is a memorandum.


//Current date and time
private Calendar now = Calendar.getInstance();
year = now.get(Calendar.YEAR);
monthOfYear = now.get(Calendar.MONTH);
dayOfMonth = now.get(Calendar.DAY_OF_MONTH);

Even if I do it, it goes back a month ago

Calendar.MONTH seems to start from 0.



 So

``` java

//Current date and time
private Calendar now = Calendar.getInstance();
year = now.get(Calendar.YEAR);
monthOfYear = now.get(Calendar.MONTH) + 1;
dayOfMonth = now.get(Calendar.DAY_OF_MONTH);

Let's write.

Recommended Posts

Calendar.MONTH
Calendar.MONTH starts from 0