Java Day From daysSince(Date since)

Here you can find the source of daysSince(Date since)

Description

days Since

License

Apache License

Declaration

public static List<Date> daysSince(Date since) 

Method Source Code

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

import java.util.*;

public class Main {
    public static List<Date> daysSince(Date since) {
        List<Date> list = new ArrayList<Date>();
        Date today = getMidnight(new Date());

        for (Date d = getMidnight(since); d.before(today)
                || d.equals(today); d = newDateFrom(d, Calendar.DAY_OF_YEAR, 1)) {
            list.add(d);/*from ww  w  .  ja  va 2  s.  c  o  m*/
        }

        return list;
    }

    /**
     * @param date a date
     * @return a new date with same day, month and year as <code>date</code>,
     *         but with hours, minutes and seconds set to zero.
     */
    public static Date getMidnight(Date date) {
        if (date == null)
            throw new IllegalArgumentException("'date' was null");

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }

    public static Date newDateFrom(Date reference, int field, int distance) {
        Calendar c = Calendar.getInstance();
        c.setTime(reference);
        c.add(field, distance);
        return c.getTime();
    }
}

Related

  1. daysAndHours(int hours)
  2. daysBetweenTime(long start, long end)
  3. daysInFebruary(int year)
  4. daysInMonthForYear(int commonMonthIndex, int yearInteger)
  5. daysOfTwo(Date date1, Date date2)
  6. dayStartTime(int day)
  7. distanceToNowInDaysIgnoreTime(Date date)
  8. equalsDay(final Date date1, final Date date2)
  9. explDay(Date date)