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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:50:34+00:00 2026-06-11T14:50:34+00:00

Friends,I am trying to calculate the difference between two date&time entries that the user

  • 0

Friends,I am trying to calculate the difference between two date&time entries that the user is providing me. The logic I am using is the code snippet shared below. Please correct me where I am going wrong and do help with solution also.

 private void CalculateDifference(String arrDate, String arrTime,
                String deptDate, String deptTime) {

            String arrival=arrDate+" "+arrTime;
            String dept=deptDate+" "+deptTime;
            System.out.println("Inside calculate diff");
            System.out.println("ARRIVAL IS"+arrival);
            System.out.println("DEPARTURE IS"+dept);
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            Date date1 = null;
            Date date2 = null;
            try {
                date1 = format.parse(arrival);
                date2 = format.parse(dept);
                System.out.println("ARRIVAL IN TRY IS"+date1);
                System.out.println("DEPARTURE IN TRY IS"+date2);
                long difference = date2.getTime() - date1.getTime(); 
                System.out.println("Time Difference is"+difference);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }

LOG-CAT

09-20 11:38:57.569: I/System.out(20028): Inside calculate diff
09-20 11:38:57.569: I/System.out(20028): ARRIVAL IS30-April  - 2012 11:38
09-20 11:38:57.569: I/System.out(20028): DEPARTURE IS20-Sept  - 2012 11:38
09-20 11:38:57.569: W/System.err(20028): java.text.ParseException: Unparseable date: "30-April  - 2012 11:38"
09-20 11:38:57.569: W/System.err(20028):    at java.text.DateFormat.parse(DateFormat.java:626)
09-20 11:38:57.569: W/System.err(20028):    at com.travel.tracker.Add.CalculateDifference(Add.java:84)
09-20 11:38:57.569: W/System.err(20028):    at com.travel.tracker.Add.onClick(Add.java:66)
09-20 11:38:57.569: W/System.err(20028):    at android.view.View.performClick(View.java:2485)
09-20 11:38:57.579: W/System.err(20028):    at android.view.View$PerformClick.run(View.java:9080)
09-20 11:38:57.579: W/System.err(20028):    at android.os.Handler.handleCallback(Handler.java:587)
09-20 11:38:57.579: W/System.err(20028):    at android.os.Handler.dispatchMessage(Handler.java:92)
09-20 11:38:57.579: W/System.err(20028):    at android.os.Looper.loop(Looper.java:130)
09-20 11:38:57.579: W/System.err(20028):    at android.app.ActivityThread.main(ActivityThread.java:3687)
09-20 11:38:57.579: W/System.err(20028):    at java.lang.reflect.Method.invokeNative(Native Method)
09-20 11:38:57.579: W/System.err(20028):    at java.lang.reflect.Method.invoke(Method.java:507)
09-20 11:38:57.579: W/System.err(20028):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
09-20 11:38:57.579: W/System.err(20028):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
09-20 11:38:57.579: W/System.err(20028):    at dalvik.system.NativeStart.main(Native Method)
  • 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-11T14:50:35+00:00Added an answer on June 11, 2026 at 2:50 pm

    For SimpleDateFormat to work you need formatter string and string you pass in the same format ie. in your case yyyy-MM-dd HH:mm

    So 30-April - 2012 11:38 should be 2012-04-30 11:38

    From DateFormat Java doc which is parent class of SimpleDateFormat you can specify month in following format.

    Sept is still not a valid month name in any format.

    M -> 9
    MM -> 09
    MMM -> Sep
    MMMM -> September 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a list of user's friends using fb connect for the
We are two friends trying to develop an application on local network using symfony
I'm trying to query for a user's facebook friends events using FQL. I've used
I'm trying get online friends by user in XMPP server (Ejabberd). I'm using Ruby
I am trying to get the friends of a test user using facebook graph
I am trying to get the Connections or user's friends info from LinkedIn using
I'm trying to find out if friends of a user have liked a page
Friends, I am trying to rotate image using css3. On w3schools i found :
What I'm trying to do: I work with two friends on a university project,
hello friends i am trying to get a list of user id and want

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.