Back
The method which you are using is the hard way, instead of that, you can use SimpleDateFormat. Below is the code, you can take it as a reference:
String intellipaat = "January 2, 2010";DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);Date date = format.parse(intellipaat);System.out.println(date); // Sat Jan 02 00:00:00 GMT 2010
String intellipaat = "January 2, 2010";
DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
Date date = format.parse(intellipaat);
System.out.println(date); // Sat Jan 02 00:00:00 GMT 2010
I hope this will help.
Want to become a Java Expert? Join Java Training now!!
Want to know more about Java? Watch this video on Java Training | Java Course for Beginners:
31k questions
32.8k answers
501 comments
693 users