Java TimeUnit Usage rangeOf(final Date date, final int beforeDates, final int afterDates)

Here you can find the source of rangeOf(final Date date, final int beforeDates, final int afterDates)

Description

range Of

License

Apache License

Declaration

public static List<Date> rangeOf(final Date date, final int beforeDates, final int afterDates) 

Method Source Code

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

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class Main {
    public static final long DATE = TimeUnit.DAYS.toMillis(1);

    public static List<Date> rangeOf(final Date date, final int beforeDates, final int afterDates) {
        final Calendar c = Calendar.getInstance();
        c.setTime(date);//from w w w  .java 2  s.c o m
        final int size = beforeDates + afterDates + 1;
        final List<Date> list = Arrays.asList(new Date[size]);
        list.set(beforeDates, date);
        for (int i = beforeDates; i > 0;) {
            c.add(Calendar.DATE, -1);
            list.set(--i, c.getTime());
        }
        c.add(Calendar.DATE, size);
        final int j = beforeDates + 1;
        for (int i = size; i > j;) {
            c.add(Calendar.DATE, -1);
            list.set(--i, c.getTime());
        }
        return list;
    }
}

Related

  1. prettyMillis(long mil)
  2. printTimeMap(Map timeMap)
  3. printTimeString(long time)
  4. printTiming(long start, long end)
  5. randomNanos(Random rand, int decimalDigits)
  6. roundTimestampToNexDay(long timestamp)
  7. run(Callable task, long timeout)
  8. second(long second)
  9. seconds(long timeInMillis)