Here you can find the source of getDateDiscrepancy(String startDate, String endDate)
public static Map<String, Long> getDateDiscrepancy(String startDate, String endDate)
//package com.java2s; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; public class Main { private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static Map<String, Long> getDateDiscrepancy(String startDate, String endDate) { try {//from www . j av a 2s . c o m Map<String, Long> result = new HashMap<String, Long>(); Date start = dateFormat.parse(startDate); Date end = dateFormat.parse(endDate); long allsecond = (end.getTime() - start.getTime()) / 1000; long day = allsecond / (24 * 3600); long hour = allsecond % (24 * 3600) / 3600; long minute = allsecond % 3600 / 60; long second = allsecond % 60; result.put("day", day); result.put("hour", hour); result.put("minute", minute); result.put("second", second); return result; } catch (ParseException e) { return null; } } public static Timestamp getTime() { return new Timestamp(new Date().getTime()); } }