Why Does Java Print 1900‑01‑01 08:05:43? Uncovering Hidden Timezone Bugs

A Java program that formats "1900-01-01 08:00:00" unexpectedly prints "1900-01-01 08:05:43" due to historic Shanghai timezone offsets, and the article walks through the bug, related OpenJDK issues, Stack Overflow cases, and how different TZDB releases affect the result.

Programmer DD
Programmer DD
Programmer DD
Why Does Java Print 1900‑01‑01 08:05:43? Uncovering Hidden Timezone Bugs

Yesterday I saw an interesting article about a obscure Java date‑formatting bug. The sample program formats a date “1900‑01‑01 08:00:00” but actually prints “1900‑01‑01 08:05:43”. The discrepancy is caused by historical timezone offsets in Shanghai.

public class MainTest {
    public static void main(String[] args) throws Exception {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse("1900-01-01 08:00:00");
        System.out.println(simpleDateFormat.format(date));
    }
}

The output differs because the timezone database records a UTC+8:05:43 offset for Shanghai in 1900. A related OpenJDK bug (JDK‑8266262) and older Stack Overflow questions show similar anomalies for the year 1927, where a midnight rollback of 5 minutes 52 seconds caused a 353‑second difference.

Investigation of the IANA Time Zone Database (TZDB) reveals that different TZDB releases (e.g., 2013a, 2014f) change the recorded transition times, which explains why the same code can produce 1 second, 353 seconds, or 358 seconds depending on the version.

In summary, Java applies a uniform rule that treats any instant before 1900‑01‑01 UTC as standard time, then adds the historical offset and any additional seconds introduced by past timezone adjustments, resulting in the observed “8:05:43” output.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavadatetimeTimezoneJDK bugTZDB
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.