Calendar.add not returning expected date
I have the following code:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM HH:mm:ss");
Date convertedDate;
String initialDate = "2011-13-05 11:00:00";
try {
Calendar cal = Calendar.getInstance();
cal.setTime(dateFormat.parse(initialDate));
cal.add(Calendar.DAY_OF_MONTH, 7);
convertedDate = cal.getTime();
String delayDate = dateFormat.format(convertedDate);
} catch (ParseException e) {
e.printStack开发者_如何学编程Trace();
}
I am expecting delayDate to contain "2011-20-05 11:00:00" but instead it is returning "2012-12-01 11:00:00" and I don't know why
It works for me both on the desktop and on an Android device. Not sure why you're getting incorrect dates.
EDIT: what specific handset are you using, and what timezone is it in?
精彩评论