Convert Month String to Integer in Java

You could parse the month using SimpleDateFormat:

    Date date = new SimpleDateFormat("MMM", Locale.ENGLISH).parse("Feb");
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int month = cal.get(Calendar.MONTH);
    System.out.println(month == Calendar.FEBRUARY);

Be careful comparing int month to an int (it does not equal 2!). Safest is to compare them using Calendar‘s static fields (like Calendar.FEBRUARY).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)