开发者

Calendar.add not returning expected date

开发者 https://www.devze.com 2023-03-05 13:22 出处:网络
I have the following code: SimpleDateFormat dateFormat = new SimpleDateFormat(\"yyyy-dd-MM HH:mm:ss\");

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消