Why Does Java SimpleDateFormat Add 5 Minutes 43 Seconds to 1900 Dates?
The article explains a mysterious Java date‑formatting bug where parsing "1900-01-01 08:00:00" with SimpleDateFormat yields "1900-01-01 08:05:43", tracing the cause to historic Shanghai timezone offsets and changes in the IANA TZ database across JDK versions.
In this article the author shares a puzzling Java date‑time behavior where formatting the date 1900-01-01 08:00:00 with SimpleDateFormat unexpectedly yields 1900-01-01 08:05:43.
The discrepancy originates from the historical timezone offset for Shanghai in the year 1900, which was UTC +8:05:43, as documented by the IANA time‑zone database and the OpenJDK bug JDK-8266262 .
The author also revisits a classic StackOverflow question about a 1927‑12‑31 time‑shift that produced a 353‑second difference, explaining that the Shanghai time zone jumped back by 5 minutes 52 seconds at that midnight, and that different versions of the TZDB (2013a, 2014f) alter the reported offset.
Because Java adopts the TZDB data, older JDK versions exhibited the larger offset, while newer versions show the corrected 1‑second difference. The article includes code examples that reproduce the behavior and screenshots of bug reports and historical timezone tables.
Ultimately the author concludes that the extra 5 minutes 43 seconds in the 1900 output is a legacy artifact of pre‑1900 timezone handling, and that the issue is considered a known bug rather than a fixable defect.
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));
}
} public static void main(String[] args) throws ParseException {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str3 = "1927-12-31 23:54:07";
String str4 = "1927-12-31 23:54:08";
Date sDt3 = sf.parse(str3);
Date sDt4 = sf.parse(str4);
long ld3 = sDt3.getTime() / 1000;
long ld4 = sDt4.getTime() / 1000;
System.out.println(ld4 - ld3);
}Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
