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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:35:47+00:00 2026-05-22T20:35:47+00:00

I am formatting my date as follows: String inputDateString = aMessage.getString(updated_at); DateTimeFormatter fmt =

  • 0

I am formatting my date as follows:

String inputDateString = aMessage.getString("updated_at");
                        DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();

                        DateTime date = fmt.parseDateTime(inputDateString);
                        DateTime now = new DateTime();
                        Period period = new Period(date, now);

                        PeriodFormatter formatter = new PeriodFormatterBuilder()
                            .appendSeconds().appendSuffix(" seconds ago\n")
                            .printZeroNever()
                            .toFormatter();

                        String elapsed = formatter.print(period);

                        dateTextView.setText(elapsed);

I would like to be able to show:

3 seconds ago if the period is less than 60 seconds
3 minutes ago if the period is less than 60 minutes
3 hours ago is the period is less than X hours
3 days ago if the period is less than X days 

etc. etc.

How can I achieve this?

  • 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-22T20:35:47+00:00Added an answer on May 22, 2026 at 8:35 pm

    Have a look at the methods available on Period, in particular those such as toStandardSeconds(). Using these it should be straightforward to achieve what you’re after with a few if-else statements making tests such as

    if (period.toStandardSeconds().getSeconds() < 60) {
       // form second-based string
    }
    else if (period.toStandardMinutes().getMinutes() < 60) {
       // ...
    

    I think the PeriodFormatter is a red herring in this case, as I don’t think it’s possible to construct a single formatter that does what you want – and in the if blocks you can just get the seconds/hours/etc. directly using the same method calls as in the conditionals.

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

Sidebar

Related Questions

We currently have a utilities class that handles a lot of string formatting, date
PHP date provides formatting for date as follows a for am,pm or A for
Is it possible to change default formatting of Date object in JSP pages? Now
Is it possible to include the day suffix when formatting a date using DateTime.ToString()?
I'm having a hard time Parsing/Formatting a Date string received back from a web
im trying to formatting the date field 'created_at' from Twitter API response with Zend_Date.
Is there an inbuilt .NET date formatting function to return a date in the
I am using DateTimePicker with Australian date formatting set (dd/mm/yyyy) The problem is when
The string formatting concept found in sprintf can be found in almost any language
I am using JODA for formatting a Date of type : 2012-01-05T08:00:00.000Z (For the

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.