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 9196287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:49:04+00:00 2026-06-17T21:49:04+00:00

I use JodaTime library for time operations. I have two dates: Date One: DateTime

  • 0

I use JodaTime library for time operations.
I have two dates:
Date One:

DateTime time_server = new DateTime(server_time_milisecs).
    withZone(DateTimeZone.forID("Europe/Zurich"));  //+0100

Shows: 2013-01-27 13:44:42

Date two:

DateTime time_local = new DateTime(DateTime.now()).
    withZone(DateTimeZone.getDefault());    //Have "Europe/Moscow" timezone  +0400

Shows: 2013-01-27 16:41:47

I need to find real interval including timezone

Interval interval = new Interval(time_local, time_server);
Long.toString(interval.toDurationMillis()));

Result: 174040 miliseconds – NOT CORRECT

int secs = Seconds.secondsBetween(time_local,time_server).getSeconds();

Result: 174 secs NOT CORRECT

Period period = new Period(time_local, time_server);
Integer.toString(period.getSeconds()) //**Wrong too**

Result must be: 10974 secs

  • 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-06-17T21:49:05+00:00Added an answer on June 17, 2026 at 9:49 pm

    You should spend some time (no pun intended) to grasp the Jodatime concepts (eg) if you need to do time calculations involving different timezones.

    For example, consider the following code

    DateTime nowHere = DateTime.now();
    DateTime nowZur = nowHere.withZone(DateTimeZone.forID("Europe/Zurich"));
    System.out.println("now Here:   " + nowHere );
    System.out.println("now Zurich: " + nowZur  );
    

    This outputs (for me, 4 hours offset from Zurich) :

    now Here:   2013-01-27T10:19:24.460-03:00
    now Zurich: 2013-01-27T14:19:24.460+01:00
    

    Pause and try to guess the output of the following lines:

    Interval interv = new Interval(nowHere, nowZur);
    System.out.println("Interval: " + interv.toDurationMillis());
    

    The above prints 0 (zero). As it should.

    Because nowHere and nowZur represent the same instant of time (in the physical line time), as represented in two different countries. They differ only in how they are represented, but physically they are the same time point (like 2.54 cm and 1 in are the same length, represented in two different forms).

    Likewise, 2013-01-27T10:19:24.460-03:00 and 2013-01-27T14:19:24.460+01:00 are the same instant, the moment in which I run that code, only represented according the conventions of different countries; a martian could represent that same instant with his own martian calendar, and it would still be the same instant.

    As those DateTimes represent the same time point, the physical interval (duration) between them must be zero. Now, if you want to get the “civil time difference” between the two, that’s a wholly different thing. The LocalDateTime and the Period (totally different from DateTime and Duration) would then be the right concepts. For example:

    Period per=new Period(nowHere.toLocalDateTime(),nowZur.toLocalDateTime());
    System.out.println(per.toStandardSeconds().getSeconds());
    

    This prints 14400 for me (4 “standard” -not physical- hours)

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

Sidebar

Related Questions

I am using Joda-Time library to convert my String dates to a real date,
What library can I use to calculate dates based on date expressions? A date
I have a Map<DateTime,Integer> rawCount , which contains raw count per date (a time-series
I use jodatime to parse date time strings as follows: public static void main(String[]args){
I'm trying to use JodaTime in Scala. So I did import org.joda.time.DateTime val dt
I am using the Joda-Time library in Java, and have a date and time
I'm trying to use the Joda Time library for my Android app to have
Just idly wondering really, the DateTime class in the awesome JodaTime library has a
Joda-Time library includes different datetime classes DateTime - Immutable replacement for JDK Calendar DateMidnight
I'm trying to use Joda-Time in order to know time durations between two points

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.