getDay() returns the day of the week, so this is wrong. Use getDate() .
getMonth() starts from scratch, so you need to add 1 to it.
getYear() returns a value that is the result of subtracting 1900 from the year, so you need to add 1900 to it.
abcd - well, you explicitly add this to the end of the line so that there are no surprises :)
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy"); Date myDate; try { myDate = df.parse(date); String myText = myDate.getDate() + "-" + (myDate.getMonth() + 1) + "-" + (1900 + myDate.getYear()); Log.i(TAG, myText); } catch (ParseException e) { e.printStackTrace(); }
They are all out of date, although you really should use Calendar .
Edit: Calendar quick example
Calendar cal = Calendar.getInstance(); cal.setTime(myDate); cal.get(Calendar.DAY_OF_MONTH);
source share