Code:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYYMMdd", Locale.US);
Object o = simpleDateFormat.parse("20111216");
System.out.println(simpleDateFormat.format((Date)o));
Output
20111226
Why? Giant bug?
I think the greater question hinted by the op on this has been missed.
Why is it that sometimes 'Y' works despite the docs. Yes it should be 'y', but on some systems 'Y' works.
I developed on a mac where 'Y' worked and it blew up on prod Linux where 'Y' didn't work. Not hard to realize what's going on, but very annoying.
一旦我修复了模式(应该是yyyyMMdd
并使用小写y
),代码就会按预期工作(输出20111216
)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.