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

The Archive Base Latest Questions

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

I’m trying to set my Period object using the millis constructor and have all

  • 0

I’m trying to set my Period object using the “millis” constructor and have all the relevant fields be updated accordingly (years, months, weeks, days, hours, minutes, seconds)

That is, using the following code:

mPeriod = new Period(millis, PeriodType.standard());

doesn’t fill all the relevant fields accordingly.
only weeks and minutes (for input millis of 1325965615539)

can someone please help me figure this thing out ?

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

    You can normalize it using Period#normalizedStandard();

    However, there’s no way Period can “fill in all the relevant fields”, because it can’t make assumptions about the number of days in months or years. The best it can do is to turn it into weeks, days, and time fields.

    The Javadoc touches on this, but not in great detail:

    If the period contains years or months, then the months will be
    normalized to be between 0 and 11. The days field and below will be
    normalized as necessary, however this will not overflow into the
    months field
    . Thus a period of 1 year 15 months will normalize to 2
    years 3 months. But a period of 1 month 40 days will remain as 1 month
    40 days.

    (Emphasis mine)

    If you need it to normalize into years and months, you need to construct the Period with values in those fields.

    Alternatively, you could use a Duration:

    1. Construct a Duration with milliseconds
    2. Use Duration#toPeriodFrom(ReadableInstant) to create a Period starting at a given instant in time (e.g. new DateTime()). According to the docs, this should work:

      This conversion will determine the fields of a period accurately. The
      results are based on the instant millis, the chronology of the
      instant, the standard period type and the length of this duration.


    Here’s what normalize() should do to your millisecond input:

    import org.joda.time.Period;
    
    class Normalize {
            public static void main(String[] args) {
                    Period period = new Period(1325965615539L);
                    System.out.println(period);
                    System.out.println(period.normalizedStandard());
            }
    }
    
    // outputs
    PT368323H46M55.539S
    P2192W2DT19H46M55.539S
    

    Notice the second line has been normalized, but only up to weeks.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.