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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:57:26+00:00 2026-06-06T11:57:26+00:00

The two different code snippets(with minor change) show some error in calculations by joda

  • 0

The two different code snippets(with minor change) show some error in calculations by joda time api:

First one: Gives correct result

DateTime date1 = new DateTime(2010,1,5, 0, 0, 0, 0);
DateTime date2 = new DateTime(2012,6,11, 0, 0, 0, 0);
Period age =new  Period(date1,date2);
System.out.println(age.getYears()+" years "+age.getMonths()+" months "+age.getDays()+" days");

Gives result : 2 years 5 months 6 days

Second one: Gives incorrect result

Change in snippet: DateTime date2 = new DateTime(2012,6,12, 0, 0, 0, 0);

DateTime date1 = new DateTime(2010,1,5, 0, 0, 0, 0);
DateTime date2 = new DateTime(2012,6,12, 0, 0, 0, 0);
Period age =new  Period(date1,date2);
System.out.println(age.getYears()+" years "+age.getMonths()+" months "+age.getDays()+" days");

Gives result : 2 years 5 months 0 days

Is this an error of calculation or am I missing some configuration?

  • 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-06T11:57:27+00:00Added an answer on June 6, 2026 at 11:57 am

    I believe this is because the 7 days are now 1 week. What happens is that the largest possible value of time which will encapsulate the remainder will always be used.

    I.E. If you have 8 days, this is 1 week and 1 day. If you have 294 days (depending on the start date), this is 1 year, 1 month, 1 week, and 1 day. Etc…

    So what you need is something like:

    System.out.println(age.getYears()+” years “+age.getMonths()+” months “+ (age.getWeeks()*7 + age.getDays()) +” days”);

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

Sidebar

Related Questions

I'm trying to make a code that will show two different images depending on
These two code snippets produce files with different file-permissions. Example 1 creates the expected
I have these two pieces of code. The first one works perfectly: UIView *tmp
Please consider the two snippets of code (the first prints Local eval, the second
I have some Scala code that does something nifty with two different versions of
Rephrasing the question: Are this two code snippets different in any way? CREATE OR
In two different views I have the following two pieces of code. FIRST <table
The following two different code snippets seem equivalent to me: var myArray = Array();
Why are these two snippets of code giving two different results? double sum =
What is the difference between the following two snippets of code: using (Object o

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.