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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:19:13+00:00 2026-06-12T20:19:13+00:00

Brief Java question: I have this code: // edited above } else if ((now

  • 0

Brief Java question:

I have this code:

// edited above

} else if ((now >= (1000 * 60 * 60 * 24) && (now < (1000 * 60 * 60 * 48)))) {
            now = (now / (1000 * 60 * 60 * 24));
            time = String.valueOf(now + " day ago");


} else if ((now >= (1000 * 60 * 60 * 48) && (now < (1000 * 60 * 60 * 24 * 30)))) {
            now = (now / (1000 * 60 * 60 * 24));
            time = String.valueOf(now + " days ago");

You can see what I am doing. If something happened between 24-48 hours ago, it was “1 day ago”, but if it was between 48 hours and 1 month (or 30 days) it was “X day*s* ago.” I am not sure how to put the month in this situation. If I delete the right side of the second if statement… it works. It will say 3 days ago, or 15 days ago, of 376 days ago. Obviously, after 30 days, I want it to say over 1 month ago…. but based on how it is, something that is, for example, 15 days ago, will not register inside that clause and it will skip. Am I missing something really small here?

Supplementary code:

Here is the entire thing in context; everything works up until “days”:

    lCDateTime = Calendar.getInstance();
    now = lCDateTime.getTimeInMillis();

    now = now - total;

    if (now <= ((1000 * 60 * 1))) {
        now = (now / 1000);
        time = String.valueOf(now + " seconds ago");

    } else if ((now > (1000 * 60 * 1)) && (now < 1000 * 60 * 2)) {
        now = (now / (1000 * 60));
        time = String.valueOf(now + " minute ago");

    } else if ((now >= (1000 * 60 * 2)) && (now < 1000 * 60 * 60)) {
        now = (now / (1000 * 60));
        time = String.valueOf(now + " minutes ago");

    } else if ((now >= (1000 * 60 * 60) && now < (1000 * 60 * 60 * 2))) {
        now = (now / (1000 * 60 * 60));
        time = String.valueOf(now + " hour ago");

    } else if ((now >= (1000 * 60 * 60 * 2) && (now < (1000 * 60 * 60 * 24)))) {
        now = (now / (1000 * 60 * 60));
        time = String.valueOf(now + " hours ago");

    } else if ((now >= (1000 * 60 * 60 * 24) && (now < (1000 * 60 * 60 * 48)))) {
        now = (now / (1000 * 60 * 60 * 24));
        time = String.valueOf(now + " day ago");

    } else if ((now >= (1000 * 60 * 60 * 48) && (now < (1000 * 60 * 60 * 24 * 30)))) {
        now = (now / (1000 * 60 * 60 * 24));
        time = String.valueOf(now + " days ago");
  • 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-12T20:19:14+00:00Added an answer on June 12, 2026 at 8:19 pm

    Your last statement

    else if ((now >= (1000 * 60 * 60 * 48) && (now < (1000 * 60 * 60 * 24 * 30))))
    

    can never be true since (1000 * 60 * 60 * 24 * 30) equals -1702967296 (aka overflow). If you really insist on doing it like this, use BigInteger. However I strongly advise you to rewrite your code.

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

Sidebar

Related Questions

i need to implement this scenario Brief about that is have two java based
brief overview so this is in context, I have an application in java that
Brief intro about my requirement. I have an empty JSF dataTable. Now, when I
EDIT: See my working code in the answers below. In brief: I have a
Brief question What command can I use to make my DataSet refresh it's connection
Brief Idea about the flow : I have say minimum 1 and maximum 18
In brief: What is the pattern called in the following code, and how should
Here's a brief rundown of my issue: I have a JavaScript function that gets
This is a follow up to this question , where I didn't get any
In brief, my question is about member variables as pointers in unmanaged C++. In

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.