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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:05:32+00:00 2026-06-13T09:05:32+00:00

So I am trying to subtract 2 dates I have come up with this

  • 0

So I am trying to subtract 2 dates I have come up with this code :

java.text.DateFormat df = new java.text.SimpleDateFormat("hh:mm:ss_yyyy.MM.dd");
java.util.Date date1 = new java.util.Date();
java.util.Date date2 = df.parse("00:00:00_2013.01.01");
long diff = date2.getTime() - date1.getTime();

But the problem is the diff isn’t correct.

Can anybody tell me what I am doing wrong ?

  • 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-13T09:05:33+00:00Added an answer on June 13, 2026 at 9:05 am

    Your diff sample in the comment is wrong. I tried your code and got this result:

    try {
        DateFormat df = new SimpleDateFormat("hh:mm:ss_yyyy.MM.dd");
        Date date1 = new java.util.Date();
        Date date2 = df.parse("00:00:00_2013.01.01");
        long diff = date2.getTime() - date1.getTime();
        Log.e("TEST" , date1.getTime() + " - " + date2.getTime() + " - " + diff);
    } catch (ParseException e) {
        Log.e("TEST", "Exception", e);
    }
    
    date1: 1350921506492
    date2: 1356994800000
    diff: 6073293508
    
    diff / 1000 / 60 / 60 / 24 = 70,292748935
    

    And roughly checked 70 days until new year sounds solid.

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

Sidebar

Related Questions

I have been trying to convert between timezones a given date and time. Code
I have two arrayLists and I am trying to subtract one arrayList from another.
What I am trying to do is to subtract 7 hours from a date.
I have a bit of (Java) that I where I am trying to simply
Possible Duplicate: how to calculate difference between two dates using java I'm trying something
I am trying to create a function that can subtract between 2 dates but
I'm trying to subtract two values from each other using twos compliment. I have
I'm trying to add or subtract some days to inputs that I have. In
I'm trying to subtract 2 character vectors containing date time information in the following
I'm trying to subtract two dates and expecting some floating values return. But what

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.