Solved

datetime subtraction

Posted on 2002-03-03
1
1,045 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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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 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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now