Java Day of isDiffIsBiggerThanMin(Date lastLogIn, Date now, Long daysL)

Here you can find the source of isDiffIsBiggerThanMin(Date lastLogIn, Date now, Long daysL)

Description

is Diff Is Bigger Than Min

License

Open Source License

Declaration

public static boolean isDiffIsBiggerThanMin(Date lastLogIn, Date now, Long daysL) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.concurrent.TimeUnit;

public class Main {
    static final String DATEFORMAT = "yyyy-MM-dd";

    public static boolean isDiffIsBiggerThanMin(Date lastLogIn, Date now, Long daysL) {
        long diffinDays = diffInDays(lastLogIn, now);
        Boolean resultValue = diffinDays > daysL;
        return resultValue;
    }/*  www  .j ava  2  s  . c o  m*/

    public static Long diffInDays(Date date1, Date date2) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);

            String lastUpdateInUTCString = sdf.format(date1);
            String nowInUTCString = sdf.format(date2);

            Date lastUpdateInUTC;

            lastUpdateInUTC = stringDateToDate(lastUpdateInUTCString);

            Date nowInUTC = stringDateToDate(nowInUTCString);

            long nowInUTCMilis = nowInUTC.getTime();
            long lastUpdateInUTCMilis = lastUpdateInUTC.getTime();

            long diff = nowInUTCMilis - lastUpdateInUTCMilis;

            TimeUnit tu = TimeUnit.DAYS;
            long diffinDays = tu.convert(diff, TimeUnit.MILLISECONDS);
            return diffinDays;
        } catch (ParseException e) {
            return Long.MIN_VALUE;
        }

    }

    public static String format(Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT);
        return dateFormat.format(date);
    }

    public static Date stringDateToDate(String StrDate) throws ParseException {
        Date dateToReturn = null;
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT);

        try {
            dateToReturn = (Date) dateFormat.parse(StrDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return dateToReturn;
    }
}

Related

  1. getTwoDay2String(String startDate, String endDate, Format format)
  2. getWorkingDay(Calendar d1, Calendar d2)
  3. getYesday()
  4. getYYYY_MM_DD(int offsetDays)
  5. isBirthdayPartAvail(String number)
  6. isEndOfDay(GregorianCalendar cal1)
  7. isHoliday(Date date, String[] excludes, String[] includes)
  8. isIn(int reserveDayCount, String dateString)
  9. isInAllDayFormat(String date)