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

  • Home
  • SEARCH
  • 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 8578703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:27:08+00:00 2026-06-11T20:27:08+00:00

I have to calculate the difference between two dates. Here is my code: System.out.println(date1

  • 0

I have to calculate the difference between two dates. Here is my code:

        System.out.println("date1  "+date1);
        System.out.println("date2  "+date2);

        totalDifference=date2.getSeconds()-date1.getSeconds();

        System.out.println("Total Difference is"+totalDifference);

The problem that I am facing is that the result is 0:

 09-24 17:24:53.839: I/System.out(9317): date1  Wed Aug 15 00:00:00 GMT+05:30 2012
 09-24 17:24:53.839: I/System.out(9317): date2  Mon Sep 24 17:24:00 GMT+05:30 2012
 09-24 17:24:53.839: I/System.out(9317): Total Difference is 0

What I am doing wrong?

Thanks guys for the solution and other valuable resources,Please help me for this question also.
Hey suppose if I enter 31st Aug 23:59:00 and next date 1 Sept 00:02:00 , I need to show the record as 1 day. Please help me for this one

  • 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-11T20:27:09+00:00Added an answer on June 11, 2026 at 8:27 pm

    getSeconds() return the second of the date,
    so in your examaple,

    date1 Wed Aug 15 00:00:00 GMT+05:30 2012

    date2 Mon Sep 24 17:24:00 GMT+05:30 2012

    In both cases, the second of the date is 0. If you want the difference you have an example in

    Android/Java – Date Difference in days

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

Sidebar

Related Questions

Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
I have to calculate the difference in hours (decimal type) between two dates in
I have a function to calculate the difference between two dates. function getDateDifference($to, $from,
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
I have code to calculate the percentage difference between 2 numbers - (oldNum -
How do I calculate the difference between two dates to display as a number
I have a two dates $date1=03/17/2012 9:00 PM; $date2=03/17/2012 9:40 PM; I have to
I have two timestamps in HH:mm format and I need to calculate difference between

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.