为什么 SimpleDateFormat 解析 Date 的月份和日期有误?
Why is SimpleDateFormat parsing Date with wrong Month and Day?
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM DD HH:mm:ss z yyyy");
try {
String d1 = list.get(position).getTaskTime(); //here d is "Tue Nov 06 15:37:51 EST 2016"
date = sdf.parse(d);
String d2=date.toString();
Log.d("demo", d2); //here d2 is "Sat Jan 06 15:37:51 EST 2016"
} catch (ParseException e) {
e.printStackTrace();
}
PS:我使用日历 class 添加 10 个月并使日期正确,这是一种 hack 但有效。但是,我想知道我的代码有什么问题。
DD
是错误的。 D
是一年中的某一天。每年的第六天是 1 月 6 日。
你应该使用 dd
.
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM DD HH:mm:ss z yyyy");
try {
String d1 = list.get(position).getTaskTime(); //here d is "Tue Nov 06 15:37:51 EST 2016"
date = sdf.parse(d);
String d2=date.toString();
Log.d("demo", d2); //here d2 is "Sat Jan 06 15:37:51 EST 2016"
} catch (ParseException e) {
e.printStackTrace();
}
PS:我使用日历 class 添加 10 个月并使日期正确,这是一种 hack 但有效。但是,我想知道我的代码有什么问题。
DD
是错误的。 D
是一年中的某一天。每年的第六天是 1 月 6 日。
你应该使用 dd
.