public static void main(String[] args) { String dateStart = "2014-01-08 00:00:00"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date d1 = null; Date d2 =new Date(); try { d1 = format.parse(dateStart); // 毫秒ms long diff = (d2.getTime() - d1.getTime());//两个时间相差 long diffSeconds = diff / 1000 % 60;//秒 long diffMinutes = diff / (60 * 1000) % 60;//分钟 long diffHours = diff / (60 * 60 * 1000) % 24;//消失 long diffDays = diff / (24 * 60 * 60 * 1000);//天 long hours=diff/(60 * 60 * 1000);//总小时 System.out.print("两个时间相差:"); System.out.print(diffDays + " 天, "); System.out.print(diffHours + " 小时, "); System.out.print(diffMinutes + " 分钟, "); System.out.print(diffSeconds + " 秒."); System.out.println(hours);//总小时 } catch (Exception e) { e.printStackTrace(); } }