Solved

datetime subtraction

Posted on 2002-03-03
1
1,048 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 50
How do I remove an object from a 3 40
sql import cannot be resolved jsp 3 45
What browser will run Java? 7 54
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

839 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