java - How to get month number from Calender -


line holds month name given user. display month number.

example: june -> 6

present code:

string line="june"; int monthno = integer.parseint(gregoriancalendar.class.getfield(line.touppercase()).get(line))+1; system.out.println(monthno); 

what best method this?
edit:
using existing calender classes

java's calendar api not best api around. many people therefore changed use http://www.joda.org/joda-time/ quasi alternative standard. if application simple, think hard-coding map of names pointing numbers easiest , efficient solution (assuming, string in fact user input, otherwise, use enum suggested). alternatively, can use date format.


Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -