Here you can find the source of getMsBetween(Date startDate, Date endDate)
public static long getMsBetween(Date startDate, Date endDate)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { public static long getMsBetween(Date startDate, Date endDate) { Calendar cal = getCalendar(); cal.setTime(startDate);/*from w w w . j av a 2 s. c o m*/ long startMs = cal.getTimeInMillis(); cal.setTime(endDate); long endMs = cal.getTimeInMillis(); return endMs - startMs; } public static Calendar getCalendar() { return getCalendar("GMT"); } public static Calendar getCalendar(String timezone) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone(timezone)); return cal; } }