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

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -