Java Time Different calculateExecutionTimeDiff(String startDate, String endDate)

Here you can find the source of calculateExecutionTimeDiff(String startDate, String endDate)

Description

calculate Execution Time Diff

License

Open Source License

Declaration

public static double calculateExecutionTimeDiff(String startDate, String endDate) 

Method Source Code

//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("&nbsp;", " ");
        endDate = endDate.replace("&nbsp;", " ");
        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
    }
}

Related

  1. createDate(String strDate, int[] timeDiff, boolean plusDiff)
  2. diffTime(String sTime, String fTime, String Dateformat1)
  3. getDiffDateTime(int diff)
  4. getDifferent(final Date timeFrom, final Date timeTo)