Java Date Difference diffDates(long starttime, long endtime, int type)

Here you can find the source of diffDates(long starttime, long endtime, int type)

Description

diff Dates

License

Open Source License

Declaration

public static long diffDates(long starttime, long endtime, int type) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {

    public static long diffDates(long starttime, long endtime, int type) {
        long result = endtime - starttime;

        switch (type) {
        case 1:// w w  w  . j a  va2  s.  c  om
            result = result / (1000 * 60 * 60 * 24 * 365);
            break;
        case 2:
            result = result / (1000 * 60 * 60 * 24 * 30);
            break;
        case 3:
            result = result / (1000 * 60 * 60 * 24);
            break;
        case 4:
            result = result / (1000 * 60 * 60);
            break;
        case 5:
            result = result / (1000 * 60);
            break;
        case 6:
            result = result / 1000;
            break;
        default:
            break;
        }
        return result;
    }

    public static long diffDates(Date startdate, Date enddate, int type) {
        return diffDates(startdate.getTime(), enddate.getTime(), type);
    }
}

Related

  1. diffCommercial(Date dateUntil, Date dateFrom, boolean bAddDay)
  2. diffDate(Date date, Date date1)
  3. diffDate(java.util.Date date, java.util.Date date1)
  4. diffDateD(Date sd, Date ed)
  5. diffDateM(Date sd, Date ed)
  6. diffDateSec(java.util.Date date, java.util.Date date1)
  7. diffDay(Date date1, Date date2)
  8. diffDay(Date start, Date end)
  9. diffDay(Date startDate, Date endDate)