Here you can find the source of getSecondsOfTowDiffDate(String p_startDate, String p_endDate)
public static long getSecondsOfTowDiffDate(String p_startDate, String p_endDate) throws ParseException
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.util.Date; public class Main { public static long getSecondsOfTowDiffDate(String p_startDate, String p_endDate) throws ParseException { return (long) getMillisOfTowDiffDate(p_startDate, p_endDate) / 1000; }//from w w w. java 2s . c o m public static long getMillisOfTowDiffDate(String p_startDate, String p_endDate) throws ParseException { Date l_startDate = toUtilDateFromStrDateByFormat(p_startDate, "yyyy-MM-dd HH:mm:ss"); Date l_endDate = toUtilDateFromStrDateByFormat(p_endDate, "yyyy-MM-dd HH:mm:ss"); long l_startTime = getMillisOfDate(l_startDate); long l_endTime = getMillisOfDate(l_endDate); return (long) (l_endTime - l_startTime); } public static long getMillisOfTowDiffDate(Date p_startDate, Date p_endDate) { long l_startTime = getMillisOfDate(p_startDate); long l_endTime = getMillisOfDate(p_endDate); return (long) (l_endTime - l_startTime); } public static java.util.Date toUtilDateFromStrDateByFormat(String p_strDate, String p_format) throws ParseException { java.util.Date l_date = null; java.text.DateFormat df = new java.text.SimpleDateFormat(p_format); if (p_strDate != null && (!"".equals(p_strDate)) && p_format != null && (!"".equals(p_format))) { l_date = df.parse(p_strDate); } return l_date; } public static long getMillisOfDate(java.util.Date p_date) { java.util.Calendar c = java.util.Calendar.getInstance(); c.setTime(p_date); return c.getTimeInMillis(); } }