Hacker News new | ask | show | jobs
by hafthor 2731 days ago
Java:

new java.text.SimpleDateFormat("YYYY-MM-dd").parse("2018-12-30") returns Sun Dec 31 2017

new java.text.SimpleDateFormat("YYYY-MM-dd").format(new java.util.Date("12/30/2018")) returns 2019-12-30

java.time from Java8 also affected.

java.time.format.DateTimeFormatter.ofPattern("YYYY-MM-dd").format(java.time.LocalDate.parse("2018-12-30")) returns 2019-12-30

2 comments

Javadoc uses yyyy for year since at least 1.5

https://docs.oracle.com/javase/1.5.0/docs/api/java/text/Simp...

I've never seen YYYY used in Java.

Isn't it fun that while we're all discussing 'yyyy' vs 'YYYY', it sees like we're missing out that what everyone actually should use most of the time is rather 'uuuu'?
Yes, indeed so. That's why I answered in the java thread. Sorry for not making that clear.