Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6192717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:59:29+00:00 2026-05-24T02:59:29+00:00

If I run the following program, which parses two date strings referencing times 1

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:59:29+00:00Added an answer on May 24, 2026 at 2:59 am

    It’s a time zone change on December 31st in Shanghai.

    See this page for details of 1927 in Shanghai. Basically at midnight at the end of 1927, the clocks went back 5 minutes and 52 seconds. So "1927-12-31 23:54:08" actually happened twice, and it looks like Java is parsing it as the later possible instant for that local date/time – hence the difference.

    Just another episode in the often weird and wonderful world of time zones.

    If rebuilt with version 2013a of TZDB, The original question would no longer demonstrate quite the same behaviour. In 2013a, the result would be 358 seconds, with a transition time of 23:54:03 instead of 23:54:08.

    I only noticed this because I’m collecting questions like this in Noda Time, in the form of unit tests… The test has now been changed, but it just goes to show – not even historical data is safe.

    In TZDB 2014f, the time of the change has moved to 1900-12-31, and it’s now a mere 343 second change (so the time between t and t+1 is 344 seconds, if you see what I mean).


    To answer a question around a transition at 1900… it looks like the Java time zone implementation treats all time zones as simply being in their standard time for any instant before the start of 1900 UTC:

    import java.util.TimeZone;
    
    public class Test {
        public static void main(String[] args) throws Exception {
            long startOf1900Utc = -2208988800000L;
            for (String id : TimeZone.getAvailableIDs()) {
                TimeZone zone = TimeZone.getTimeZone(id);
                if (zone.getRawOffset() != zone.getOffset(startOf1900Utc - 1)) {
                    System.out.println(id);
                }
            }
        }
    }
    

    The code above produces no output on my Windows machine. So any time zone which has any offset other than its standard one at the start of 1900 will count that as a transition. TZDB itself has some data going back earlier than that, and doesn’t rely on any idea of a "fixed" standard time (which is what getRawOffset assumes to be a valid concept) so other libraries needn’t introduce this artificial transition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following error when i try to run a console program which
Hey everyone, I am trying to run the following program, but am getting a
I have the following layout for my test suite: TestSuite1.cmd: Run my program Check
Whenever I run any jython program in Eclipse, I got the following error in
I want to run the following code: ajaxUpdate(10); With a delay of 1 second
As an experiment i am trying to write the following program which allows me
I'm getting following linker error when I compile my program with VS2008 solution which
I get the following error when I try to run my java program(it's supposed
I have the following C99 program which measures performance of simple division operations relative
When I run the following, PowerShell hangs waiting for the dialog to close, even

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.