Seeya K
Seeya K

Reputation: 1321

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?

Upvotes: 0

Views: 183

Answers (2)

boriswaguia
boriswaguia

Reputation: 41

By yyyy/mm/dd I guest you mean years/Months/days. So you may try using
yyyy/MM/dd (note upcase use of MM).

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

Upvotes: 1

Alexi Akl
Alexi Akl

Reputation: 1942

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) {
    }

Upvotes: 3

Related Questions