Here you can find the source of getTwoTimeInterval(String startTime, String endTime, String format)
public static long getTwoTimeInterval(String startTime, String endTime, String format)
//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; } }