Java Today getTodayIntevalDays(String date)

Here you can find the source of getTodayIntevalDays(String date)

Description

get Today Inteval Days

License

Open Source License

Declaration

public static long getTodayIntevalDays(String date) 

Method Source Code

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

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

import java.util.Date;

public class Main {

    public static long getTodayIntevalDays(String date) {
        try {//from   w w w . jav  a2  s. co m
            Date currentDate = new Date();
            SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
            java.util.Date theDate = myFormatter.parse(date);
            long days = (currentDate.getTime() - theDate.getTime()) / (24 * 60 * 60 * 1000);

            return days;
        } catch (Exception ee) {
            return 0l;
        }
    }

    public static long getTodayIntevalDays(Date date) {
        try {

            Date currentDate = new Date();
            long days = (currentDate.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);

            return days;
        } catch (Exception ee) {
            return 0l;
        }
    }

    public static Date parse(String strDate, String pattern) throws ParseException {
        try {
            return getFormatter(pattern).parse(strDate);
        } catch (ParseException pe) {
            throw new ParseException("Method parse in Class DateUtil  err: parse strDate fail.",
                    pe.getErrorOffset());
        }
    }

    private static SimpleDateFormat getFormatter(String parttern) {
        return new SimpleDateFormat(parttern);
    }
}

Related

  1. getTodayFormat(String format)
  2. getTodayFormatString(String pattern)
  3. getTodayFormatted(String pattern)
  4. getTodayHHmmss(String HHmmss)
  5. getTodayInFormat(String format)
  6. getTodayLast()
  7. getTodayLastSecond()
  8. getTodayLastSecond()
  9. getTodayLastUpdateTimeFormat()