Solved

datetime subtraction

Posted on 2002-03-03
1
1,050 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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…
Suggested Courses

751 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