Here you can find the source of diffTime(String sTime, String fTime, String Dateformat1)
public static int diffTime(String sTime, String fTime, String Dateformat1) throws Exception
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static int diffTime(String sTime, String fTime) throws Exception { SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date stime = myFormatter.parse(sTime); java.util.Date ftime = myFormatter.parse(fTime); int second = (int) ((ftime.getTime() - stime.getTime()) / 1000); return second; }// ww w . j ava 2s . co m public static int diffTime(String sTime, String fTime, String Dateformat1) throws Exception { SimpleDateFormat myFormatter = new SimpleDateFormat(Dateformat1); java.util.Date stime = myFormatter.parse(sTime); java.util.Date ftime = myFormatter.parse(fTime); int second = (int) ((ftime.getTime() - stime.getTime()) / 1000); return second; } public static String getTime() { Calendar calendar = Calendar.getInstance(); String strHour = "" + calendar.get(Calendar.HOUR_OF_DAY); if (strHour.length() == 1) strHour = "0" + strHour; String strMinute = "" + calendar.get(Calendar.MINUTE); if (strMinute.length() == 1) strMinute = "0" + strMinute; String strSecond = "" + calendar.get(Calendar.SECOND); if (strSecond.length() == 1) strSecond = "0" + strSecond; String curTime = strHour + strMinute + strSecond; return curTime; } }