Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Java by (13.1k points)
I was trying to convert a string into a date format, so for that I have break the details element like day, month and year into integer. Is there any other way to do this?

1 Answer

0 votes
by (26.7k points)

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

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:

Related questions

0 votes
1 answer
asked Sep 30, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Dec 26, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 24, 2019 in Java by Nigam (4k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...