为什么SimpleDateFormat解析日期和错误的月份和日期? [英] Why is SimpleDateFormat parsing Date with wrong Month and Day?
本文介绍了为什么SimpleDateFormat解析日期和错误的月份和日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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:我使用Calendar类添加了10个月,并设置了正确的日期,这有点像hack,但是可以用.但是,我想知道我的代码出了什么问题.
PS: I used Calendar class to add 10 months and made the date right which is kind of a hack but works. But, I want to know what's wrong with my code.
推荐答案
DD
是错误的. D
是一年中的一天.每年的第六天是1月6日.
DD
is wrong. D
is day of year. Sixth day of year is January 6.
您应该使用 dd
.
文档: SimpleDateFormat
这篇关于为什么SimpleDateFormat解析日期和错误的月份和日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文