Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
I was trying to create a date object in Java. But, I cannot able to find any easy way. Is there any easy way available?

1 Answer

0 votes
by (26.7k points)

In able to create a date object, we can use calendar function like:

 Date date = new GregorianCalendar(2014, Calendar.FEBRUARY, 11).getTime();

Also, you can try the below method to create a date object:

public static Date parseDate(String date) {

     try {

         return new SimpleDateFormat("yyyy-MM-dd").parse(date);

     } catch (ParseException e) {

         return null;

     }

  }

I hope this will help.

Want to know more about Java? Prefer this tutorial on Java Tutorial.

Want to become a Java Expert? join Java Certification now!!

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...