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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:43:09+00:00 2026-06-02T02:43:09+00:00

I want to find difference between current system time and inserted data&time String .

  • 0

I want to find difference between current system time and inserted data&time String. I have tried this:

 try {

            String strFileDate = "2012-04-19 15:15:00";
            DateFormat formatter2 = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
            Date date = formatter2.parse(strFileDate);
            long difference = date.getTime() - System.currentTimeMillis();
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(difference);
            Toast.makeText(getBaseContext(),
                    formatter2.format(calendar.getTime()), Toast.LENGTH_LONG)
                    .show();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

but it does not give me the right result. Am I doing it right?

Update

I tried following ::

String strFileDate = "2012-04-19 15:15:00";
            DateFormat formatter2 = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
            Date date = formatter2.parse(strFileDate);
            long diffInMs = date.getTime()
                    - new Date(System.currentTimeMillis()).getTime();

            long diffInSec = TimeUnit.MILLISECONDS.toSeconds(diffInMs);

            long hour = diffInSec / (1000 * 60 * 60);
            double minutes = diffInSec / (1000 * 60);
            // long diffInHour = TimeUnit.to(diffInMs);

            Toast.makeText(getBaseContext(),
                    "left time is :: " + hour + ":" + minutes,
                    Toast.LENGTH_LONG).show();

output::
left time is:: -2 : -131.0

UPdate(20/4/2012)

try {
            Date dt = new Date();
            String strFileDate = "2012-04-20 13:10:00";
            DateFormat formatter2 = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
            Date date = formatter2.parse(strFileDate);
            String s = getTimeDiff(dt, date);
            Log.i("Date is :: >>> ", s);
        } catch (Exception e) {
            e.printStackTrace();
        }
 public String getTimeDiff(Date dateOne, Date dateTwo) {
        String diff = "";
        long timeDiff = Math.abs(dateOne.getTime() - dateTwo.getTime());
        diff = String.format("%d hour(s) %d min(s)", TimeUnit.MILLISECONDS.toHours(timeDiff),
                TimeUnit.MILLISECONDS.toMinutes(timeDiff) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(timeDiff)));
        return diff;

}

Output::
04-20 12:48:06.629:
INFO/Date is :: >>>(1295): 2183 hour(s) 38 min(s)

  • 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-02T02:43:10+00:00Added an answer on June 2, 2026 at 2:43 am

    Use JodaTime for calculating period(Time Difference). http://joda-time.sourceforge.net/

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

Sidebar

Related Questions

I want to find difference between two time-components, but I am not getting what
I want to find time difference between two date and then compare the difference
Hallo, I want to find the difference between today and another date, convert todays
I want to find out the difference between two Dates (in terms of minutes)
I want to find out the logged in person What is the Difference between
Let's say I want to find out the difference in seconds between two times.
This is the situation here. I have current time in epoch. also I have
I want to find if there are any difference between DateTime.UtcNow . LastEdited (9/11/2011
How can I find the difference between this, for example, 1700 hours and 1020
I want to find out the time in unix time (ie seconds since the

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.