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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:58:57+00:00 2026-05-31T04:58:57+00:00

I just found a bug in a website I’m working on and I corrected

  • 0

I just found a bug in a website I’m working on and I corrected it. My problem here is that even if I corrected it I don’t understand what was the issue.

I have two dates (I can’t use GregorianCalendar) and I want to evaluate the distance between these two in days. It’s kind of trivial but my code had a weird behaviour.

For specific dates, for instance: 26/04/2008 and 26/05/2008 the number of days should be exactly 30 but I got -19. For other dates, it worked fine. Here is what I did:

    Date dMin = ... // -> 26/04/2008
    Date dMax = ... // -> 26/05/2008

    System.out.println((dMax.getTime()-dMin.getTime())/(1000*60*60*24)); // prints 30
    int i = (int) (dMax.getTime()-dMin.getTime())/(1000*60*60*24); // i = -19

So how did I correct it? I did something like this:

long i = (dMax.getTime()-dMin.getTime())/(1000*60*60*24);

And later on, just before I display it on screen, I would cast it as an integer and it’s working fine.

I’m working with GWT and this calculus is done on the client side (so it’s compiled as javascript).

Is there something I am missing there? I guess yes but I can’t find out what it is.

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

    I think there is a problem with your cast (parentheses), see for example:

    public static void main(String[] args) throws Exception {
        System.out.println((int)(1.2)*10); //prints 10
        System.out.println((int)(1.2*10)); //prints 12
    }
    

    So your int i = (int) (dMax.getTime()-dMin.getTime())/(1000*60*60*24); // i = -19 first casts dMax.getTime()-dMin.getTime() to int before dividing – you possibly get an overflow there.

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

Sidebar

Related Questions

I have found a very subtle bug in my R code just now. The
I just found a solution to one of the weirdest bug i have ever
I just found something that sounds weird with Maven plugin management. While working on
I have no idea if I just found a potential jQuery bug, but check
It was a bug that I just found! Hooray. The bug was due to
I just found a bug in my Rails app which would lead to certain
I just found a bug in one of the rake tasks shipped with Rails.
Say I just found a bug involving javascript workflow in a web app. Most
Just found out that the video output of the iPad is not a system
I just found myself creating a class called InstructionBuilderFactoryMapFactory. That's 4 pattern suffixes on

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.