Java Day End getMsBetween(Date startDate, Date endDate)

Here you can find the source of getMsBetween(Date startDate, Date endDate)

Description

get Ms Between

License

Open Source License

Declaration

public static long getMsBetween(Date startDate, Date endDate) 

Method Source Code

//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;
    }
}

Related

  1. getMonthFirstDays(Date startDate, Date endDate)
  2. getMonths(Date end, Date start)
  3. getMonthsBetweenBeginDateAndEndDate(Date beginDate, Date endDate)
  4. getMonthSpan(Date begin, Date end)
  5. getMonthSpan(Date start, Date end)
  6. getNextEndDate(Date date, int offset)
  7. getNextSendTime(Date sendDate, Date start)
  8. getNumberOfDaysBetweenDates(Date beginDate, Date endDate)
  9. getNumberOfMonthsBetween(final Date begin, final Date end)