Java Time Format getTwoTimeInterval(String startTime, String endTime, String format)

Here you can find the source of getTwoTimeInterval(String startTime, String endTime, String format)

Description

get Two Time Interval

License

Apache License

Declaration

public static long getTwoTimeInterval(String startTime, String endTime, String format) 

Method Source Code


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

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

import java.util.Date;

public class Main {
    public static final String yyyyMMddHH = "yyyyMMddHH";

    public static long getTwoTimeInterval(String startTime) {
        SimpleDateFormat df = new SimpleDateFormat(yyyyMMddHH);
        try {//from   w ww. ja v  a  2s  .  c  o m
            Date starDate = df.parse(startTime);
            return System.currentTimeMillis() - starDate.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static long getTwoTimeInterval(String startTime, String endTime) {
        return getTwoTimeInterval(startTime, endTime, yyyyMMddHH);
    }

    public static long getTwoTimeInterval(String startTime, String endTime, String format) {
        SimpleDateFormat df = new SimpleDateFormat(format);
        try {
            Date starDate = df.parse(startTime);
            Date endDate = df.parse(endTime);
            return endDate.getTime() - starDate.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }
}

Related

  1. getTimeOnlyDateFormat()
  2. getTimeOnlyWithNumber()
  3. getTimeQuantum(String strDate, String format)
  4. getTimeStringFormatedForSWANWithDelim( final Object pObjTime, final String pStrDelim)
  5. getTimeSystem(String formatTime)
  6. getUniversalDateTimeFormat()
  7. getXsdDateTimeFormat()
  8. getXSDFormatter(DateTime date)
  9. isDateFormat(String timeString)