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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:07:56+00:00 2026-06-04T06:07:56+00:00

I saw all the post in here and still I can’t figure how do

  • 0

I saw all the post in here and still I can’t figure how do get difference between two android dates.

This is what I do:

long diff = date1.getTime() - date2.getTime();
Date diffDate = new Date(diff);

and I get: the date is Jan. 1, 1970 and the time is always bigger in two hours…I’m from Israel so the two hours is timeOffset.

How can I get normal difference???

  • 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-04T06:07:57+00:00Added an answer on June 4, 2026 at 6:07 am

    You’re close to the right answer, you are getting the difference in milliseconds between those two dates, but when you attempt to construct a date out of that difference, it is assuming you want to create a new Date object with that difference value as its epoch time. If you’re looking for a time in hours, then you would simply need to do some basic arithmetic on that diff to get the different time parts.

    Java:

    long diff = date1.getTime() - date2.getTime();
    long seconds = diff / 1000;
    long minutes = seconds / 60;
    long hours = minutes / 60;
    long days = hours / 24;
    

    Kotlin:

    val diff: Long = date1.getTime() - date2.getTime()
    val seconds = diff / 1000
    val minutes = seconds / 60
    val hours = minutes / 60
    val days = hours / 24
    

    All of this math will simply do integer arithmetic, so it will truncate any decimal points

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

Sidebar

Related Questions

So I saw this post here and read it and it seems like bulk
I saw this post here , he explains well howto show a highlighted result,
I saw all the post on cookies ...still cannot make it work...may be i
I saw this algorithm that will take numbers or words and find all possible
I saw this in a random doxygen example for C#, and all attempts at
I saw that even by writing separate commands, we can combine two different types
I saw in an earlier post here on stackoverflow a example on many to
I saw an older post on here asking how to do relatively the same
So I saw this post: http://mobiledevelopertips.com/xcode/download-and-install-older-versions-of-xcode-xcode-previous-releases.html (new location: at iosdevelopertips.com ) about downloading older
Hi all this is my post on stackoverflow. I am normally a lurker and

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.