Java Day From getDateByDay(Date date)

Here you can find the source of getDateByDay(Date date)

Description

get Date By Day

License

Apache License

Declaration

public static List<Date> getDateByDay(Date date) 

Method Source Code


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

import java.util.*;

public class Main {
    public static List<Date> getDateByDay(Date date) {
        List<Date> dates = new ArrayList<>();
        Calendar c = GregorianCalendar.getInstance();
        c.setTime(date);//from   w w  w  .j a v  a2s . c  o m
        setTimeToBeginningOfDay(c);
        dates.add(c.getTime());
        setTimeToEndofDay(c);
        dates.add(c.getTime());
        return dates;
    }

    public static List<Date> getDateByDay() {
        List<Date> dates = new ArrayList<>();
        Calendar c = GregorianCalendar.getInstance();
        setTimeToBeginningOfDay(c);
        dates.add(c.getTime());
        setTimeToEndofDay(c);
        dates.add(c.getTime());
        return dates;
    }

    private static void setTimeToBeginningOfDay(Calendar calendar) {
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
    }

    private static void setTimeToEndofDay(Calendar calendar) {
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
    }
}

Related

  1. explDay(Date date)
  2. firstDayOfCentury(final int century)
  3. get23HourOfDay(Date date)
  4. getAge(Date birthDay)
  5. getBeforeDate_(Date date, int day)
  6. getDateByNum(int day)
  7. getDateFromDayNum(int dayNum)
  8. getDateUpDay(Date d)
  9. getDay(Date date)