Here you can find the source of getSecondCa(Date d1, Date d2)
public static long getSecondCa(Date d1, Date d2)
//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 long getSecondCa(Date d1, Date d2) { long quot = Math.abs(d1.getTime() - d2.getTime()); quot = quot / 1000;/*w w w. j a v a 2 s . c om*/ return quot; } public static long getSecondCa(String d1, String d2, String format) { return getSecondCa(toDate(d1, format), toDate(d2, format)); } public static long getTime(String s) { return parseMysql(s).getTime(); } public static Date toDate(String str) { if (null == str || str.trim().isEmpty()) { return null; } try { DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return fmt.parse(str); } catch (ParseException e) { return null; } } public static Date toDate(String dateString, String format) { try { DateFormat fmt = new SimpleDateFormat(format); return fmt.parse(dateString); } catch (ParseException e) { return null; } } public static Date parseMysql(String s) { try { DateFormat fmtTemp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return fmtTemp.parse(s); } catch (ParseException e) { return null; } } }