Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

datetime subtraction

Posted on 2002-03-03
1
Medium Priority
?
1,053 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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 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…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

886 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