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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:28:37+00:00 2026-06-05T04:28:37+00:00

Is there way to convert ‘x’ seconds to y hours and z seconds when

  • 0

Is there way to convert ‘x’ seconds to y hours and z seconds when say x exceeds 3600 seconds? Similarly, convert it to ‘a minutes and b seconds’ when x exceeds 60 but is less than 3600 seconds, using JodaTime? I understand that I would have to specify what I need in the PeriodFormatter, but I don’t want to specify it – I want a formatted text based on value of seconds.

This is similar to how you would post on a forum and then your post will initially be shown as ‘posted 10 seconds ago’.. after 1 minute you would see ‘posted 1minute 20 seconds ago’ and likewise for weeks,days,years.

  • 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-05T04:28:38+00:00Added an answer on June 5, 2026 at 4:28 am

    I’m not sure why you don’t want to specify what you need in PeriodFormatter. JodaTime doesn’t know how you want to display a period as a string, so you need to tell it via the PeriodFormatter.

    As 3600 seconds is 1 hour, using the formatter properly will automatically do this for you. Here’s a code example using a number of different inputs on the same formatter which should achieve your desired result.

        Seconds s1 = Seconds.seconds(3601);
        Seconds s2 = Seconds.seconds(2000);
        Seconds s3 = Seconds.seconds(898298);
        Period p1 = new Period(s1);
        Period p2 = new Period(s2);
        Period p3 = new Period(s3);
        
        PeriodFormatter dhm = new PeriodFormatterBuilder()
            .appendDays()
            .appendSuffix(" day", " days")
            .appendSeparator(" and ")
            .appendHours()
            .appendSuffix(" hour", " hours")
            .appendSeparator(" and ")
            .appendMinutes()
            .appendSuffix(" minute", " minutes")
            .appendSeparator(" and ")
            .appendSeconds()
            .appendSuffix(" second", " seconds")
            .toFormatter();
        
        System.out.println(dhm.print(p1.normalizedStandard()));
        System.out.println(dhm.print(p2.normalizedStandard()));
        System.out.println(dhm.print(p3.normalizedStandard()));
    

    Produces output::

    1 hour and 1 second

    33 minutes and 20 seconds

    3 days and 9 hours and 31 minutes and 38 seconds

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

Sidebar

Related Questions

Is there simpler way to convert CSV files to SQL file than this?: BufferedReader
Is there any way to convert String to Regexp (in Ruby)? Let's say: 'example'
Is there a way to convert twitter bootstrap's typeahead function into a $(body).on() function?
Is there any way to convert a android.graphics.Bitmap instance into jpeg in android?
Is there a way to convert a Java application into a Mac OS X
Is there a way to convert an integer to a string in PHP?
Is there a way to convert HTML into XAML? I noticed that you can
Is there any way to convert from DB.Null to decimal in C#? Like Object[]
Is there a way to convert an int to a bitmask? example: int i
Is there a way to convert a vector to a pointer to a pointer

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.