Java Week Day getDayOfWeek(Date date)

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

Description

Gets the day of the week for the specified date.

License

Apache License

Parameter

Parameter Description
date a Date object

Return

the corresponding day of the week, e.g. "Tuesday"

Declaration

public static String getDayOfWeek(Date date) 

Method Source Code


//package com.java2s;
/*/*  w  w w  . j av a2s .  c o  m*/
 *
 * $Date$
 * $Author$
 * $Revision$
 *
 * Copyright 2011-2018 the University of New Mexico.
 *
 * This work was supported by National Science Foundation Cooperative
 * Agreements #DEB-0832652 and #DEB-0936498.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 *
 */

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

public class Main {
    /**
     * Gets the day of the week for the specified date.
     * 
     * @param  date  
     *         a Date object
     * @return  
     *         the corresponding day of the week, e.g. "Tuesday"
     */
    public static String getDayOfWeek(Date date) {
        String dayOfWeek = null;
        Calendar c = Calendar.getInstance(Locale.US);

        c.setTime(date);

        switch (c.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.MONDAY:
            dayOfWeek = "Monday";
            break;
        case Calendar.TUESDAY:
            dayOfWeek = "Tuesday";
            break;
        case Calendar.WEDNESDAY:
            dayOfWeek = "Wednesday";
            break;
        case Calendar.THURSDAY:
            dayOfWeek = "Thursday";
            break;
        case Calendar.FRIDAY:
            dayOfWeek = "Friday";
            break;
        case Calendar.SATURDAY:
            dayOfWeek = "Saturday";
            break;
        case Calendar.SUNDAY:
            dayOfWeek = "Sunday";
            break;
        }

        return dayOfWeek;
    }
}

Related

  1. getCurWeekDayByStr(String curday)
  2. getDay(long date, int startOfWeek, int increment)
  3. getDayNextWeek()
  4. getDayOfTheWeekFromNow(int nDays)
  5. getDayOfWeek()
  6. getDayOfWeek(Date date)
  7. getDayOfWeek(Date date)
  8. getDayOfWeek(Date date)
  9. getDayOfWeek(Date date)