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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:31:47+00:00 2026-06-18T20:31:47+00:00

Trying to make a little Countdown program in Java. I am working on the

  • 0

Trying to make a little Countdown program in Java.

I am working on the finding the difference between the dates part of the app, and for some reason I am only getting the days.

I want the days, hours, minutes, and seconds. I am not sure why my calculation is just being rounded to an even integer… 163 in this example, and not 163.xx?

Here is my code:

import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class CalcData {

    Calendar cal1;
    Date today;

    public CalcData() {

        cal1 = new GregorianCalendar();
        today = new GregorianCalendar().getTime();

    }

    public String calcDiff() {

        cal1.set(2013, 6, 27, 7, 15, 0);
        double theDays = calcDays(cal1.getTime(), today);
        return "" + theDays;

    }

    public double calcDays(Date d1, Date d2) {

        double theCalcDays = (double) ((d1.getTime() - d2.getTime()) / (1000 * 60 * 60 * 24));
        return theCalcDays;

    }
}

When I run this, as I said, I get the result: 163.0

I would think, if it is using milliseconds, that it would be some sort of decimal. I am sure it is something simple that I am missing, but just can’t find it!

Thanks in advance!

  • 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-18T20:31:48+00:00Added an answer on June 18, 2026 at 8:31 pm

    You are dividing an integer by another integer. You need to cast those to doubles before you do the division. Like this

    double theCalcDays = ((double) (d1.getTime() - d2.getTime())) / (1000 * 60 * 60 * 24);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a little program in Java, I need it to remove
I'm trying to make a little java program that executes a system command but
I'm working on a Zappa app, and I'm currently trying to make a little
Okay so I'm trying to make a little gag program that will run away
The graph I'm currently trying to make falls a little between two stools. I
HI all. I am trying to make little program that reads data from file
I'm trying to make a little modal framework in my app.. Heres my controller:
I'm trying to make a little app that displays only images from a specific
I'm trying to make a little desktop app that should show the contents of
I'm trying to make a little app that has a little meter in it

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.