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

  • Home
  • SEARCH
  • 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 6198625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:03:02+00:00 2026-05-24T04:03:02+00:00

In the question A very strange date before 1970 , I know the reason

  • 0

In the question A very strange date before 1970, I know the reason why two times looks only have difference of 1s, but sometimes we can get another value.

For example from that question:

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 will be 353 in a timezone of Shanghai, but will be 1 in other timezones.

My question is, how to calculate the difference without timezones? How to always get the correct difference?

  • 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-24T04:03:03+00:00Added an answer on May 24, 2026 at 4:03 am

    You can easily handle timezones with Joda Time.

    • You can create a DateTimeFormatter with the desired time zone and use it to parse the string. The DateTime instances can also be converted to other time zones.

    • You can ignore timezones completely by using the LocalDateTime class.

    • Also the Period class has methods like toStandardSeconds(), toStandardDuration(), normalizedStandard() etc. which “makes the assumption that all weeks are 7 days, all days are 24 hours, all hours are 60 minutes and all minutes are 60 seconds. This is not true when daylight savings time is considered, and may also not be true for some unusual chronologies. However, it is included as it is a useful operation for many applications and business rules.”

    Here is how to construct a timezoneless LocalDateTime either directly or by conversion from a timezoneful DateTime instance.

    LocalDateTime a1 = new LocalDateTime(1927, 12, 31, 0, 0, 0, 0);
    LocalDateTime a2 = new LocalDateTime(1928, 1, 2, 0, 0, 0, 0);
    System.out.println(a1);
    System.out.println(a2);
    System.out.println(Seconds.secondsBetween(a1, a2).getSeconds()); // 172800 == 60 * 60 * 24 * 2 == 2 days without leap seconds
    
    DateTime b1 = new DateTime(1927, 12, 31, 0, 0, 0, 0, DateTimeZone.forID("Asia/Shanghai"));
    DateTime b2 = new DateTime(1928, 1, 2, 0, 0, 0, 0, DateTimeZone.forID("Asia/Shanghai"));
    System.out.println(b1);
    System.out.println(b2);
    System.out.println(Seconds.secondsBetween(b1, b2).getSeconds());
    
    LocalDateTime c1 = b1.toLocalDateTime();
    LocalDateTime c2 = b2.toLocalDateTime();
    System.out.println(c1);
    System.out.println(c2);
    System.out.println(Seconds.secondsBetween(c1, c2).getSeconds());
    

    This will print as follows. Notice the funny timezone in Shanghai time before its timezone adjustment in 1927.

    1927-12-31T00:00:00.000
    1928-01-02T00:00:00.000
    172800
    1927-12-31T00:00:00.000+08:05:52
    1928-01-02T00:00:00.000+08:00
    173152
    1927-12-31T00:00:00.000
    1928-01-02T00:00:00.000
    172800
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very strange question but I have some legacy code that interacts with another application
I have a very strange question. I have a class/function : class MCBSystem {
a noob question here. I have a very strange situation that's very puzzling to
This question was very helpful, however I have a list control in my report,
Very basic question: how do I write a short literal in C++? I know
Very direct question, i need to know if its possible and maybe where to
This is a very simple question with a simple answer, but it is not
Here's a very simple question. I have an SP that inserts a row into
I am stuck onto a very strange situation. I have a workflow that i
All, Sorry - this is probably a very strange question. I'm working on a

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.