Search code examples
javahibernatedateconvertersdate-conversion

date conversion issue in java


I accept the user input date in yyyy/mm/dd format. When I try to convert using SimpleDateFormat it shows "null";

my code for conversion is:

SimpleDateFormat dateofbirthFormat = new SimpleDateFormat("yyyy/mm/dd"); 
java.util.Date dateOfBirth = dateofbirthFormat.parse(birthdate);

why is it showing null?


Solution

  • MM not mm, MM is for months, mm is for minutes

        SimpleDateFormat dateofbirthFormat = new SimpleDateFormat("yyyy/MM/dd"); 
        try {
            java.util.Date dateOfBirth = dateofbirthFormat.parse("1986/12/11");
            System.out.println(dateOfBirth);
        } catch (ParseException e) {
        }