This is a classic Stack Overflow question regarding a peculiar Java Date/Time bug from 1927 in specific timezones, demonstrating that `ld4-ld3` is 353 seconds instead of 1. It highlights issues with historical timezone data, specifically the change from Shanghai local mean time to standard time in 1927. The problem is a specific historical anomaly rather than a general date/time library flaw.
A starter prompt for Claude Code, what you'll need, and how to reach them.
You are an expert Java developer and web developer. I need to create a project based on the Stack Overflow question 'Why is subtracting these two epoch-milli Times (in year 1927) giving a strange result?'. The goal is to build a minimal, interactive web application that demonstrates this specific Java timezone bug and provides a clear explanation. Use Next.js 16 App Router, React 19, Tailwind v4 for the frontend, and a small Java backend (using Spring Boot, perhaps) to replicate the original `SimpleDateFormat` issue and a correct `java.time` solution. The data should be simple; no database is needed. MVP: A single page showing two date input fields (with 1927-12-31 23:54:07 and 1927-12-31 23:54:08 as defaults), a timezone selector (defaulting to 'Asia/Shanghai'), and two output sections. The first output section must call the legacy Java code via an API to show the `353` result. The second output section must call modern `java.time` via an API to show `1`. Below these, provide a concise explanation (generated content is fine) about why this bug occurs (Shanghai timezone change in 1927). The app should be deployable to Vercel.
If I run the following program, which parses two date strings referencing times 1 second apart and compares them: 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); } The output is: 353 Why is ld4-ld3 , not 1 (as I would expect from the one-second difference in the times), but 353 ? If I change the dates to times 1 second later: String str3 = "1927-12-31 23:54:08"; String str4 = "1927-12-31 23:54:09"; Then ld4-ld3 will be 1 . Java version: java version "1.6.0_22" Java(TM) SE Runtime Environment (build 1.6.0_22-b04) Dynamic Code Evolution Client VM (build 0.2-b02-internal, 19.0-b04-internal, mixed mode) Timezone(`TimeZone.getDefault()`): sun.util.calendar.ZoneInfo[id="Asia/Shanghai", offset=28800000,dstSavings=0, useDaylight=false, transitions=19, lastRule=null] Locale(Locale.getDefault()): zh_CN Tags: java, date, t
No specific contact needed; this is a public problem.
“No direct outreach for this specific Stack Overflow question as it's a historical bug. The value is in building a public, educational resource. The operator can share it as a 'Show HN' or blog post.”
Open the original ↗