Java Date Between getBetweenTime(Date begin, Date end, int field)

Here you can find the source of getBetweenTime(Date begin, Date end, int field)

Description

get Between Time

License

Apache License

Declaration

public static long getBetweenTime(Date begin, Date end, int field) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static long getBetweenTime(Date begin, Date end, int field) {
        long between = (end.getTime() - begin.getTime());
        switch (field) {
        case Calendar.DATE:
            return between / (24 * 60 * 60 * 1000);
        case Calendar.HOUR:
            return between / (60 * 60 * 1000);
        case Calendar.MINUTE:
            return between / (60 * 1000);
        case Calendar.SECOND:
            return between / (1000);
        default://from   w  w  w  . j  a  va2  s .  co  m
            return between;
        }
    }
}

Related

  1. getBetweenDate(String d1, String d2)
  2. getBetweenDateBuckets(Date from, Date to)
  3. getBetweenDates(Date fromDate, Date toDate )
  4. getBetweenDays(String strFromDate, String strToDate)
  5. getBetweenMonths(Date date1, Date date2)
  6. getBetweenWorkDate(int amount, Date beginDate)
  7. isBetween(Date check, Date from, Date to)
  8. isBetween(Date date, Date d1, Date d2)