Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

February in Java Calendar

Tags:

java

calendar

I have a problem, I think that the result of this block of code should be "February", but the result is "March", what I'm doing wrong?

    import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;

public class Calendario {

        public static void main(String args[]){
            Locale locale = new Locale("es","MX");
            Calendar calendarTemp = new GregorianCalendar();
            calendarTemp.set(Calendar.MONTH,1);
            String mesTemp = calendarTemp.getDisplayName(Calendar.MONTH, Calendar.LONG, locale);
            System.out.println(mesTemp);

        }

}

Thanks for your help.

like image 891
ghdezc Avatar asked Dec 25 '22 07:12

ghdezc


1 Answers

My guess is that February 30 is coming back as March 2.

This duplicate question has the best answer: A strange behavior from java.util.Calendar on February

like image 99
Instantsoup Avatar answered Dec 28 '22 05:12

Instantsoup