Here you can find the source of getTimeDifference(Date date1, Date date2)
public static long getTimeDifference(Date date1, Date date2)
//package com.java2s; // Licensed to the Apache Software Foundation (ASF) under one import java.util.Calendar; import java.util.Date; public class Main { public static long getTimeDifference(Date date1, Date date2) { Calendar dateCalendar1 = Calendar.getInstance(); dateCalendar1.setTime(date1);//from w w w . j a v a 2 s. c o m Calendar dateCalendar2 = Calendar.getInstance(); dateCalendar2.setTime(date2); return (dateCalendar1.getTimeInMillis() - dateCalendar2 .getTimeInMillis()) / 1000; } }