Solved

datetime subtraction

Posted on 2002-03-03
1
1,049 Views
Last Modified: 2008-01-09
Hello all

How do I subtract given two strings in the format YYYYMMDDHHMMSS to get the number of seconds in between,considering all the leap years, time zone etc in java?

20020301100300 - 20020301100315 = 15 seconds

Thanks in advance
0
Comment
Question by:sugamp
1 Comment
 
LVL 6

Accepted Solution

by:
kotan earned 100 total points
ID: 6838608
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");

String strDate1, strDate2;

Date date1 = sdf.parse(strDate1);
Date date2 = sdf.parse(strDate2);

long diff = date1.getTime() - date2.getTime() / 1000;
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySqlDump not dumping triggers 1 53
Java string replace 11 61
Android development question 2 75
How do I remove an object from a 3 51
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question