Java Day End getTimeBeetweenDates(Date d1, Date d2, int timeType)

Here you can find the source of getTimeBeetweenDates(Date d1, Date d2, int timeType)

Description

get Time Beetween Dates

License

Open Source License

Declaration

public static long getTimeBeetweenDates(Date d1, Date d2, int timeType) 

Method Source Code

//package com.java2s;
/*//from   w  w w  .  j a  va 2s . c  o  m
 * Copyright (C) 2010 dungnv. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

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

public class Main {
    public static long getTimeBeetweenDates(Date d1, Date d2, int timeType) {

        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        cal1.setTime(d1);
        cal2.setTime(d2);
        long diff = d2.getTime() - d1.getTime();

        switch (timeType) {
        case Calendar.SECOND:
            return (long) diff / 1000;
        case Calendar.MINUTE:
            return (long) diff / (60 * 1000);
        case Calendar.HOUR:
            return (long) diff / (60 * 60 * 1000);
        case Calendar.DATE:
            return (long) diff / (24 * 60 * 60 * 1000);
        default:
            return diff;
        }
    }
}

Related

  1. getSecondSemesterEndDate(Integer year)
  2. getSendTime(Date sendDate, Date start, Date end)
  3. getStartAndEndDate(Date d)
  4. getStartOrEndTime(Date date, int flag)
  5. getSubSeconds(Date minuendDate, Date subDate)
  6. getTimeInterval(Date startDate, Date endDate)
  7. getTotalDays(Date startDate, Date endDate)
  8. getTotalMonths(final Date startDateToCheck, final Date endDateToCheck)
  9. getTrendTime(Date date)