Java Date Difference getDateDifference(String start, String end)

Here you can find the source of getDateDifference(String start, String end)

Description

get Date Difference

License

Apache License

Declaration

public static double getDateDifference(String start, String end) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static double getDateDifference(String start, String end) {
        double result;
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
        String start_fixed = start.substring(0, 23); // remove microseconds & timeoffset
        String end_fixed = end.substring(0, 23); // remove microseconds & timeoffset

        try {//w w  w .j  a  v  a 2s .c om
            Date startDate = format.parse(start_fixed);
            Date endDate = format.parse(end_fixed);
            result = endDate.getTime() - startDate.getTime();
            result = result / 1000;
        } catch (ParseException pe) {
            result = -1;
        }

        return result;
    }
}

Related

  1. diffY(Date endDate, Date startDate)
  2. getDateDiff(String startDate, String endDate)
  3. getDateDiff(String startDt, String endDt)
  4. getDateDiff(String startTime, String endTime)
  5. getDateDiffDay(String begindate, String enddate)
  6. getDateDifference(String startDateString, String endDateString)
  7. getDateDiffHour(String begindate, String enddate)
  8. getDayDiff(Date firstDate, Date secondDate)
  9. getDiff(Date from, Date to)