Java Day Count getDaysBetween(Map params)

Here you can find the source of getDaysBetween(Map params)

Description

get Days Between

License

Open Source License

Declaration

public static int getDaysBetween(Map<String, Object> params) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static int getDaysBetween(Map<String, Object> params) {

        String start = params.get("start_date").toString();
        String end = params.get("end_date").toString();

        Calendar startCalendar = Calendar.getInstance();
        Calendar endCalendar = Calendar.getInstance();

        Date startDate = null;//from   w w w. j a  v a 2s .  c  om

        Date endDate = null;

        try {
            startDate = new SimpleDateFormat("yy-MM-dd").parse(start);
            startCalendar.setTime(startDate);
            endDate = new SimpleDateFormat("yy-MM-dd").parse(end);
            endCalendar.setTime(endDate);
        } catch (ParseException e) {
        }
        int days = endCalendar.get(Calendar.DAY_OF_YEAR) - startCalendar.get(Calendar.DAY_OF_YEAR);

        int y2 = endCalendar.get(Calendar.YEAR);

        if (startCalendar.get(Calendar.YEAR) != y2) {
            startCalendar = (Calendar) startCalendar.clone();
            do {
                days += startCalendar.getActualMaximum(Calendar.DAY_OF_YEAR);
                startCalendar.add(Calendar.YEAR, 1);
            } while (startCalendar.get(Calendar.YEAR) != y2);
        }
        return days;
    }
}

Related

  1. getDayCount(String from, String to)
  2. getDayCount(String from, String to)
  3. getDayCount(String yyyy_mm_dd_1, String yyyy_mm_dd_2)
  4. GetDays(String strStartDate, String strEndDate)
  5. getDaysBetween(Calendar d1, Calendar d2)
  6. getDaysBetweenTwoDays(String dateFrom, String dateEnd)
  7. getDaySub(String beginDate, String endDate)
  8. getDaySub(String start_time, String end_time)