Reputation: 68
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?
Upvotes: 2
Views: 1280
Reputation: 177
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.
Upvotes: 0
Reputation: 500357
Once I fix the pattern (it should be yyyyMMdd
with lowercase y
), the code works as expected (it outputs 20111216
).
Upvotes: 0