[英]SimpleDateFormat function parse(String s) gives wrong date
As an input I have Date object(for example, exDate=Fri Aug 01 00:00:00 EEST 2014) that must be formated. 作为输入,我必须格式化Date对象(例如,exDate = Fri Aug 01 00:00:00 EEST 2014)。 After the parsing of the date, I get wrong date.
在解析日期之后,我得到了错误的日期。
SimpleDateFormat sdf = new SimpleDateFormat(
"dd-MMM-YYYY hh.mm.ss.SSSSSSSSS aa", Locale.ENGLISH);
String dateStart = sdf.format(exDate);
Date dateF = sdf.parse(dateStart);
dateStart will be equal to dateStart将等于
01-Aug-2014 12.00.00.000000000 AM
and the resut, dateF will be equal to 和resut,dateF将等于
Sun Dec 29 00:00:00 EET 2013
So, after the parsing of a string with date, the result is wrong. 因此,在解析带有日期的字符串之后,结果是错误的。 Maybe, somebody know the source of the problem?
也许,有人知道问题的根源吗? Or another way to format date in another
SimpleDateFormat
? 或者另一种在另一个
SimpleDateFormat
格式化日期的方法?
The problem is the YYYY which means : 问题是YYYY 意味着 :
Y Week year;
The actual year, which is what you are looking for would be yyyy
. 实际的一年,你正在寻找的将是
yyyy
。
I really recommend that you go in the link above to see the full list . 我真的建议你进入上面的链接查看完整列表 。
You should also replace the milliseconds to .SSS
as you can't get more precise than that. 您还应该将毫秒替换为
.SSS
因为您无法获得更精确的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.