I want to get the date , month and year from the particular date.
I have used below code :
String dob = "01/08/1990";
int month = 0, dd = 0, yer = 0;
try {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
Date d = sdf.parse(dob);
Calendar cal = Calendar.getInstance();
cal.setTime(d);
month = cal.get(Calendar.MONTH);
dd = cal.get(Calendar.DATE);
yer = cal.get(Calendar.YEAR);
} catch (Exception e) {
e.printStackTrace();
}
So from the above code i am getting month -0 , yer - 1990 and date - 8
But i want month - 01 , date - 08 and yer - 1990
.
I have defined the date format also but i am not getting perfect value from date, month and year.