Convert String month to integer java

后端 未结 2 1634
无人及你
无人及你 2021-01-15 15:03

How do I convert a month string to integer?

On click method I want to display the date which is selected but if the date has an event it should display something mo

相关标签:
2条回答
  • 2021-01-15 15:44

    There are only 12 month, so just normalize the string and just do string comparison. I wouldn't try to over-optimize.

    0 讨论(0)
  • 2021-01-15 15:49
    Calendar cal = Calendar.getInstance();
    cal.setTime(new SimpleDateFormat("MMM").parse("July"));
    int monthInt = cal.get(Calendar.MONTH) + 1;
    

    See

    • IDE one demo
    0 讨论(0)
提交回复
热议问题