Previous top articles:

1, the past selected excellent blog are here!

39 weird code comments, laughing and crying…

Awesome people, have begun to write code in Classical Chinese!

4, How to gracefully root out null bugs!

Promise me you won’t if/else walk around the world again, ok?


Yesterday I heard from a colleague that I was called back to fix the Bug on New Year’s Day because the formatting time in my project was “YYYY-MM-DD”. What happened?

Let’s see what happens first!

I. Recurrence of problems:

Note: The JDK test version is 1.7

“Yyyy-mm-dd” format time error!

Second, what is the specific reason?

This is because in the Java language, at certain times or with numbers and other data, you normally feel that everything is OK! But at a specific time, specific circumstances can go wrong! Just formatting time even one of them!

The New Year 2020 coincides with the exchange of 2019 and 2020, so there is a problem with formatting time, which is attributed to the use of “YYYY-MM-DD” formatting time!

YYYY is week-based-year, it’s 2020, and YYYY is 2019!

The Java Bible says:

YYYY indicates the year of the week in which the date is located. The week starts on Sunday and ends on Saturday. As long as the week is New Year’s day, the week is counted as the next year.

Iii. Summary:

Whether or not you have experienced such a Bug, hopefully after reading this article, you can pay attention to this detail and avoid making mistakes in the future.

Use YYYY-MM-DD for date formatting in development, and don’t use anything else!

Previous top articles:

1. The question that 188W+ programmers on Stack Overflow are all concerned about: Is Java passing by value or by reference?

Dubbo must know 18 interview questions! Catch them all!

3. Java code hacks that increase productivity a thousandfold

4. Back-end development guide!

Java backend technology (ID: JavaITWork), learn Java with 200,000 people! Reply:1024, you can get it for free! Includes SSM, Spring family bucket, microservices, MySQL, MyCat, cluster, distributed, middleware, Linux, network, multi-threading, Jenkins, Nexus, Docker, ELK and so on free learning video, continue to update!