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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:37:20+00:00 2026-05-26T16:37:20+00:00

I want to compare(finding remaining days and time between two days) using joda time.

  • 0

I want to compare(finding remaining days and time between two days) using joda time.
I am taking two DateTime object like this(one is starting and another is ending)

DateTime endDate  = new DateTime(2011,12,25,0,0,0,0);   
DateTime strtDate = new DateTime();

Now i am interested to find remaining date and time like this
days:49 Hrs:5 Min:52 Sec:45(Not considering Year and month here..)

Now I go ahead with period class like this

Period period = new Period();

PeriodFormatter formatter = new PeriodFormatterBuilder()
    .appendSeconds()
    .appendMinutes()
    .appendHours()
    .appendDays()
    .appendMonths()
    .appendYears()
    .printZeroNever()
    .toFormatter();

Now in result what i get year,month,Day,etc…
in this case i will get days between 1-30(not 31,45,49…(which I want)) always.

So how can i get this thing(is there any method that I am missing) or I need to handle this programmatically, as I read that joda time is very flexible so I am very sure that there will be any method like this.

If you are familiar then kindly share your knowledge.

  • 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-26T16:37:21+00:00Added an answer on May 26, 2026 at 4:37 pm

    Defines all standard fields from days downwards with PeriodType.dayTime().

    For example :

    DateTime startDate = DateTime.now(); // now() : since Joda Time 2.0
    DateTime endDate = new DateTime(2011, 12, 25, 0, 0);
    
    Period period = new Period(startDate, endDate, PeriodType.dayTime());
    
    PeriodFormatter formatter = new PeriodFormatterBuilder()
            .appendDays().appendSuffix(" day ", " days ")
            .appendHours().appendSuffix(" hour ", " hours ")
            .appendMinutes().appendSuffix(" minute ", " minutes ")
            .appendSeconds().appendSuffix(" second ", " seconds ")
            .toFormatter();
    
    System.out.println(formatter.print(period));
    

    Sample output

    Period between startDate and endDate is

    47 days 12 hours 46 minutes 47 seconds


    Or

    PeriodFormatter formatter = new PeriodFormatterBuilder()
            .appendPrefix("Day:", " Days:").appendDays()
            .appendPrefix(" Hour:", " Hours:").appendHours()
            .appendPrefix(" Minute:", " Minutes:").appendMinutes()
            .appendPrefix(" Second:", " Seconds:").appendSeconds()
            .toFormatter();
    

    with output

    Days:47 Hours:12 Minutes:46 Seconds:47

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

Sidebar

Related Questions

I want to compare two ms-access .mdb files to check that the data they
I want to compare records between 2 databases on my SQL 2008 Server. The
I want to compare two CSV files to see if they are different. I
I want to compare two times in VB.net: I have 1:42:21 PM and I
I want to compare two arrays, one coming from a shoppingcart and the other
Using VB6 I want to compare the system date, if the exe should not
I want to know if I can compare two consecutive jobs in Hadoop. If
I have this two strings of equal length, which I need to compare. I
I want to compare only time on client side, means the start time should
I want to compare two tabdelimeted files. I take the files and converts them

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.