简体   繁体   English

SimpleDateFormat函数解析(String s)给出错误的日期

[英]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.

相关问题 SimpleDateFormat对相同日期字符串的解析和格式给出了不同的结果 - SimpleDateFormat parse and format on same date string gives different results SimpleDateFormat和解析:解析不会因错误的输入字符串日期而失败 - SimpleDateFormat and parsing: parse doesn't fail with wrong input string date SimpleDateFormat无法将字符串解析为Date - SimpleDateFormat can not parse string to Date java中的SimpleDateFormat(“ yyyy-MM-dd'T'HH:mm:ssZ”)解析给出错误的日期? - SimpleDateFormat(“yyyy-MM-dd'T'HH:mm:ssZ”) parse in java gives wrong date? SimpleDateFormat在解析期间返回错误的日期值 - SimpleDateFormat returns wrong date value during parse DateTimeFormatter 无法解析日期字符串,但 SimpleDateFormat 能够 - DateTimeFormatter unable to parse a Date String but SimpleDateFormat is able to 为什么这个 SimpleDateFormat 不能解析这个日期字符串? - Why can't this SimpleDateFormat parse this date string? SimpleDateFormat解析具有当前日期的时间字符串 - SimpleDateFormat Parse a time string with current date SimpleDateFormat.parse() - 为不同的日期格式生成错误的日期 - SimpleDateFormat.parse() - generates wrong date for different date-formats SimpleDateFormat.parse(String)提供空值android - SimpleDateFormat.parse(String) gives null value android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM