get Day Of Week - Java java.time

Java examples for java.time:Week

Description

get Day Of Week

Demo Code


//package com.java2s;

import java.time.DayOfWeek;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static DayOfWeek getDayOfWeek(Date date) {
        DayOfWeek ret = null;/*from   ww  w .  jav  a  2  s.  co  m*/

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int day = c.get(Calendar.DAY_OF_WEEK);
        switch (day) {
        case 1:
            ret = DayOfWeek.SUNDAY;
            break;
        case 2:
            ret = DayOfWeek.MONDAY;
            break;
        case 3:
            ret = DayOfWeek.TUESDAY;
            break;
        case 4:
            ret = DayOfWeek.WEDNESDAY;
            break;
        case 5:
            ret = DayOfWeek.THURSDAY;
            break;
        case 6:
            ret = DayOfWeek.FRIDAY;
            break;
        case 7:
            ret = DayOfWeek.SATURDAY;
            break;
        default:
            break;
        }
        return ret;
    }
}

Related Tutorials