package com.kiisoo.ic.utils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 日期工具类
 */
public class DateUtils {

    /**
     * 加一天
     */
    public static Date addDay(Date date, int addNum){
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.DAY_OF_MONTH, addNum);
        return c.getTime();
    }


    public static List<Date> getdays(Date startDay, Date endDay) {
        List<Date> timeList = new ArrayList<Date>();
        Date d1 = formatHourMinuteAndSecondToZero(startDay);// 定义起始日期
        Date d2 = formatHourMinuteAndSecondToZero(endDay);// 定义结束日期
        Calendar dd = Calendar.getInstance();// 定义日期实例
        dd.setTime(d1);// 设置日期起始时间
        timeList.add(startDay);
        while (dd.getTime().before(d2)) {// 判断是否到结束日期
            dd.add(Calendar.DATE, 1);// 进行当前日期月份加1
            timeList.add(formatHourMinuteAndSecondToZero(dd.getTime()));

        }
        return timeList;
    }

    /**
     * 将Date的十分秒格式化为零
     *
     * @param date
     * @return
     * @author 朱红旭
     * @date 2017年4月19日
     * @version 1.0
     */
    public static Date formatHourMinuteAndSecondToZero(Date date) {
        Calendar calendar = Calendar.getInstance();
        if (null != date) {
            calendar.setTime(date);
        }
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        return calendar.getTime();
    }
}
