Android Day of Week Get getDayOfWeekZeroIndexed(Date dateTime)

Here you can find the source of getDayOfWeekZeroIndexed(Date dateTime)

Description

Returns the day of week as zero indexed.

Parameter

Parameter Description
dateTime to get zero-indexed day of week

Return

zero-indexed day of week

Declaration

public static int getDayOfWeekZeroIndexed(Date dateTime) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/*ww  w  . ja  va 2  s  .c o m*/
     * Returns the day of week as zero indexed.
     * That means, a dateTime in monday will return 0;
     *
     * @param dateTime to get zero-indexed day of week
     * @return zero-indexed day of week
     */
    public static int getDayOfWeekZeroIndexed(Date dateTime) {
        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(dateTime);

        final int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        switch (dayOfWeek) {
        case Calendar.MONDAY:
            return 0;
        case Calendar.TUESDAY:
            return 1;
        case Calendar.WEDNESDAY:
            return 2;
        case Calendar.THURSDAY:
            return 3;
        case Calendar.FRIDAY:
            return 4;
        case Calendar.SATURDAY:
            return 5;
        case Calendar.SUNDAY:
            return 6;
        default:
            throw new IllegalStateException();
        }
    }
}

Related

  1. getDayOfWeek(String year, String month, String day)
  2. getDayOfWeek(String date)
  3. getDayOfWeek(Date date)
  4. getFirstDayOfWeek()
  5. getDayOfTheWeek(Date date)
  6. getReadableWeekDay(int day)
  7. getStringDayOfWeek(Date date)
  8. getDayOfWeek(String format, int calendarField)
  9. getDayOfWeek(String format, int calendarField)