Java Day Between getDifferDays(String date1, String date2)

Here you can find the source of getDifferDays(String date1, String date2)

Description

get Differ Days

License

Apache License

Declaration

public static long getDifferDays(String date1, String date2) 

Method Source Code


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

import java.text.SimpleDateFormat;

import java.util.*;

public class Main {
    static public SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");

    public static long getDifferDays(String date1, String date2) {
        Date tempDate1 = str2date(date1);
        Date tempDate2 = str2date(date2);
        long differDays = 0;
        differDays = tempDate2.getTime() - tempDate1.getTime();
        long todaySeconds = 1000 * 24 * 60 * 60;
        return differDays / todaySeconds + 1;
    }// w  w w . j a  v a  2s  . c o m

    public static Date str2date(String str) {
        Date result = null;
        try {
            Date udate = yyyyMMdd.parse(str);
            result = new Date(udate.getTime());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String getTime(String parrten) {
        String timestr;
        if (parrten == null || parrten.equals("")) {
            parrten = "yyyyMMddHHmmss";
        }
        java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);
        java.util.Date cday = new java.util.Date();
        timestr = sdf.format(cday);
        return timestr;
    }
}

Related

  1. getDaysDifference(final Date begin, final Date end)
  2. getDiffBetweenQuarter(Date latestDate, Date current)
  3. getDiffDays(Date date1, Date date2)
  4. getDiffDays(String startDate, String endDate)
  5. getDifferDays(Date d1, Date d2)
  6. getDifference(Date d1, Date d2)
  7. getDifferenceInDays(final Date startDate, final Date endDate)
  8. getDifferenceOfDays(String dateFromStr, String dateToStr, String dateFormat)
  9. getDifferencesBetweenIndicateDays( final Date minorDate, final Date majorDate)