Java Time Different getTimeDiff(String start, String end, String format, int timeDiff)

Here you can find the source of getTimeDiff(String start, String end, String format, int timeDiff)

Description

get time diff between start and end using format

License

Open Source License

Exception

Parameter Description
IOException an exception

Declaration

public static long getTimeDiff(String start, String end, String format, int timeDiff) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**//ww  w.  j a  v a 2 s.c  o  m
     * get time diff between start and end using format
     * @throws IOException 
     */
    public static long getTimeDiff(String start, String end, String format, int timeDiff) throws IOException {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat(format);
            Date d1 = dateFormat.parse(start);
            Date d2 = dateFormat.parse(end);
            return ((d1.getTime() - d2.getTime()) / timeDiff);
        } catch (ParseException e) {
            throw new IOException("can't parse date, start:" + start + " end:" + end);
        }
    }
}

Related

  1. getDifferent(final Date timeFrom, final Date timeTo)
  2. getDiffTime(Date beforeTime, Date afterTime)
  3. getDiffTime(long startTime)
  4. getDiffTime(String strDate, int idx)
  5. getFormattedTimeWithDiff(DateFormat dateFormat, long finishTime, long startTime)
  6. getTimeDiffMin(String format, String startDate, String endDate)
  7. isDateDiff_2(String pattern, String time2, String time1)
  8. isLowerThanMinTimeDiff(Date lastUpdate, Date now, Long minTimeDiff)
  9. printTimeDiff(Long oldDate, Long newDate, String message)