Java Day of Week getDay(long date, int startOfWeek, int increment)

Here you can find the source of getDay(long date, int startOfWeek, int increment)

Description

get Day

License

Open Source License

Declaration

private static long getDay(long date, int startOfWeek, int increment) 

Method Source Code


//package com.java2s;
import java.util.Calendar;

public class Main {
    private static Calendar CALENDAR = Calendar.getInstance();

    private static long getDay(long date, int startOfWeek, int increment) {
        Calendar calendar = CALENDAR;
        synchronized (calendar) {
            calendar.setTimeInMillis(date);
            int day = calendar.get(Calendar.DAY_OF_WEEK);
            // Normalize the view starting date to a week starting day
            while (day != startOfWeek) {
                calendar.add(Calendar.DATE, increment);
                day = calendar.get(Calendar.DAY_OF_WEEK);
            }/*from  w  w  w. j  a v  a  2 s.  c o m*/
            return startOfDayInMillis(calendar.getTimeInMillis());
        }
    }

    /**
    * Returns day in millis with the hours, milliseconds, seconds and minutes
    * set to 0.
    *
    * @param date long used in calculating start of day
    * @return Start of <code>date</code>
    */
    public static long startOfDayInMillis(long date) {
        Calendar calendar = CALENDAR;
        synchronized (calendar) {
            calendar.setTimeInMillis(date);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            return calendar.getTimeInMillis();
        }
    }
}

Related

  1. getDateForCurrentWeekDay(int day)
  2. getDateOfWeek(int week)
  3. getDateOfWeek(int year, int weekOfYear, int i)
  4. getDateOfYearWeek(int yearNum, int weekNum, int dayOfWeek)
  5. getDateWeek(String date)
  6. getDayAfterGivenDate(Date date, int dayOfWeek)
  7. getDayOfWeek()
  8. getDayOfWeek(Date date)
  9. getDayOfWeek(int _year, int _month, int _day)