Here you can find the source of getTimeStr(String date1, String date2)
public static String getTimeStr(String date1, String date2)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String getTimeStr(String date1, String date2) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); try {//from w w w .j av a 2 s. co m long time = format.parse(date1).getTime() - format.parse(date2).getTime(); long time1 = format.parse("1970-01-01 00:00:00").getTime() + time; return formatDate(new Date(time1), "HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } return ""; } public static long getTime(String time) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { return format.parse("1970-01-01 " + time).getTime() - format.parse("1970-01-01 00:00:00").getTime(); } catch (ParseException e) { e.printStackTrace(); } return 0; } public static String formatDate(Date date, String formatGeshi) { SimpleDateFormat format = new SimpleDateFormat(formatGeshi); return format.format(date); } }