Here you can find the source of calculateExecutionTimeDiff(String startDate, String endDate)
public static double calculateExecutionTimeDiff(String startDate, String endDate)
//package com.java2s; /*/*from w w w.j av a 2s .c om*/ * This file is part of UnitTH * * UnitTH is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * UnitTH is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with UnitTH if not, see <http://www.gnu.org/licenses/>. * * ======================================================================= * $Id: TestItemUtils.java,v 1.6 2010/05/04 21:26:14 andnyb Exp $ * ----------------------------------------------------------------------- * * ======================================================================= */ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static double calculateExecutionTimeDiff(String startDate, String endDate) { Date start = null; Date end = null; startDate = startDate.replace(" ", " "); endDate = endDate.replace(" ", " "); DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); try { start = formatter.parse(startDate); end = formatter.parse(endDate); } catch (ParseException dfe) { dfe.printStackTrace(); return 0.0; } long timeDiff = (end.getTime() - start.getTime()) / 1000; // Milli seconds / 1000 return (double) timeDiff; // seconds } }