Java Day Between getBetweenTwoDayCalender(String startDay, String endDay)

Here you can find the source of getBetweenTwoDayCalender(String startDay, String endDay)

Description

get Between Two Day Calender

License

Open Source License

Declaration

public static List<String> getBetweenTwoDayCalender(String startDay, String endDay) 

Method Source Code


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

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

import java.util.Date;

import java.util.List;

public class Main {
    public static List<String> getBetweenTwoDayCalender(String startDay, String endDay) {
        List<String> list = new ArrayList<String>();
        if (startDay == null || startDay.equals("")) {
            return null;
        }//from  w w w.j  a v a2 s.co  m
        if (endDay == null || endDay.equals("")) {
            return null;
        }
        SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date startD = myFormatter.parse(startDay);
            Date endD = myFormatter.parse(endDay);
            long day = (endD.getTime() - startD.getTime()) / (24 * 60 * 60 * 1000);
            long dayMill = 24 * 60 * 60 * 1000;
            int d = Integer.parseInt(String.valueOf(day));
            String updateTime;
            long longTime;
            for (int i = 0; i <= d; i++) {
                longTime = startD.getTime() + dayMill * i;
                updateTime = myFormatter.format(new Date(longTime));
                list.add(updateTime);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return list;
    }
}

Related

  1. differentDaysByMillisecond(Date date1, Date date2)
  2. diffInDays(Date date1, Date date2)
  3. getBeteenDays(String begin, String end, String format)
  4. getBetweenDays(long longValue1, long longValue2)
  5. getBetweenDays(String start, String end)
  6. getDateDiff(Date date, int day)
  7. getDateDiff(final Date startDate, final Date endDate)
  8. getDateDifference(Date date1, Date date2)
  9. getDateDifferenceinDays(Date date1, Date date2)