Java Day of Week javaCalendarToNewTimeApi(int dayOfWeek)

Here you can find the source of javaCalendarToNewTimeApi(int dayOfWeek)

Description

The method is intended to convert Calendar day of week to DayOfWeek .

License

Apache License

Parameter

Parameter Description
dayOfWeek Calendar day of week to convert

Exception

Parameter Description
IllegalArgumentException if dayOfWeek is not a constant from Calendar

Return

converted from day of week

Declaration

public static DayOfWeek javaCalendarToNewTimeApi(int dayOfWeek) 

Method Source Code

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

import java.time.DayOfWeek;

import java.util.Calendar;

public class Main {
    /**/*w  w  w  . ja v  a 2s.c  o  m*/
     * The method is intended to convert {@link Calendar} day of week to {@link DayOfWeek}.
     *
     * @param dayOfWeek {@link Calendar} day of week to convert
     * @return {@link DayOfWeek} converted from {@link Calendar} day of week
     * @throws IllegalArgumentException if dayOfWeek is not a constant from {@link Calendar}
     */
    public static DayOfWeek javaCalendarToNewTimeApi(int dayOfWeek) {
        switch (dayOfWeek) {
        case Calendar.MONDAY:
            return DayOfWeek.MONDAY;
        case Calendar.TUESDAY:
            return DayOfWeek.TUESDAY;
        case Calendar.WEDNESDAY:
            return DayOfWeek.WEDNESDAY;
        case Calendar.THURSDAY:
            return DayOfWeek.THURSDAY;
        case Calendar.FRIDAY:
            return DayOfWeek.FRIDAY;
        case Calendar.SATURDAY:
            return DayOfWeek.SATURDAY;
        case Calendar.SUNDAY:
            return DayOfWeek.SUNDAY;
        default:
            throw new IllegalArgumentException("Unknown day of week number: [" + dayOfWeek + "]");
        }
    }
}

Related

  1. isWeekend(Date dt)
  2. isWeekEnd(Date in)
  3. isWeekend(final Date date)
  4. isWeekendDay(final DayOfWeek nDayOfWeek)
  5. isWork(String weekday, Date date)
  6. mergeDayIntoDate(Date baseDate, int dayOfWeek)
  7. nextDayOfWeek(Date fromDate, int dow)
  8. nextWeek(Date date)
  9. nextWeek(final Date date)