Back
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; } }
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!!
31k questions
32.8k answers
501 comments
693 users