When I create a Date from parsing a String and access the day of the month, I get the wrong value.
Date datearr = null;
DateFormat df1 = new SimpleDateFormat("dd-MM-yyyy");
String dataa = "17-03-2012";
try {
datearr = df1.parse(dataa);
} catch (ParseException e) {
Toast.makeText(this, "err", 1000).show();
}
int DPDMonth = datearr.getMonth() + 1;
int DPDDay = datearr.getDay();
int DPDYear = datearr.getYear() + 1900;
System.out.println(Integer.toString(DPDDay)+"-"+Integer.toString(DPDMonth)+"-"+Integer.toString(DPDYear));
Why do I get 0 instead of 17?
03-11 10:24:44.286: I/System.out(2978): 0-3-2012
Here’s a snippet the doesn’t use deprecated methods anymore, fixes naming issues and simplifies the output.