Advertisement

04.28.2005 at 07:05AM PDT, ID: 21405796
[x]
Attachment Details

Java Subtracting Dates

Asked by radixk in Java Programming Language

Tags: java, subtracting, dates

I have a small twist to the many,many questions already posted for this never ending problem.

How to find the number of minutes between two dates?  The below code, does not take
the day in mind, so if end time is earlier than start time, the result is negative.


start = "2005/04/25 16:00:29";
end = "2005/04/26 13:21:15";

SimpleDateFormat sdf = new SimpleDateFormat("yyyy/dd/mm H:mm:ss");
Date s = sdf.parse(start);
Date e = sdf.parse(end);
            
Calendar scal = java.util.GregorianCalendar.getInstance();
scal.setTime(s);
Calendar ecal =java.util.GregorianCalendar.getInstance();
ecal.setTime(e);
                  
long result = (e.getTime() - s.getTime())/60000;


result ===>   -158 !

Start Free Trial
[+][-]04.28.2005 at 07:06AM PDT, ID: 13885728

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 07:13AM PDT, ID: 13885790

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 07:16AM PDT, ID: 13885826

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 07:18AM PDT, ID: 13885869

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: java, subtracting, dates
Sign Up Now!
Solution Provided By: TimYates
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.28.2005 at 07:21AM PDT, ID: 13885906

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 07:22AM PDT, ID: 13885914

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 07:22AM PDT, ID: 13885917

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 07:23AM PDT, ID: 13885927

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 07:25AM PDT, ID: 13885947

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 07:25AM PDT, ID: 13885950

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 07:31AM PDT, ID: 13886037

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 07:36AM PDT, ID: 13886091

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2005 at 11:01AM PDT, ID: 13888358

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32