Java Day of Week extractDayOfWeek(Date date)

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

Description

Extract the day of the week from a Date instance.

License

Apache License

Parameter

Parameter Description
date the date instance from which the day of week is to be extracted.

Return

the day of the week from the specified instance. Sunday is represented by 1, Monday by 2, through to Saturday by 7. These correspond to the values returned by . The constants , ... may prove useful.

Declaration


public static int extractDayOfWeek(Date date) 

Method Source Code

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

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

public class Main {
    /**/* ww  w .j a v  a2 s .  c  o  m*/
     * Extract the day of the week from a {@link Date} instance.
     *
     * @param date the date instance from which the day of week is to be extracted.
     * @return the day of the week from the specified {@link Date} instance.
     *         Sunday is represented by 1, Monday by 2, through to Saturday by 7.
     *         These correspond to the values returned by {@link java.util.Calendar#get(int)}.
     *         The constants {@link java.util.Calendar#SUNDAY}, {@link java.util.Calendar#MONDAY} ... may prove useful.
     */

    public static int extractDayOfWeek(Date date) {

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);

        return cal.get(Calendar.DAY_OF_WEEK);

    }
}

Related

  1. dayOfWeek(int year, int month, int day)
  2. dayOfWeekFromInt(final int theDay)
  3. dayOfWeekFromInteger(String aDay, boolean longName)
  4. dayOfWeekNames()
  5. endOfWeek(Date inDate, TimeZone timeZone)
  6. findDayOfWeek(String threeLetters)
  7. firstDateAfterAddWeeks(Date early, int weeks)
  8. firstDayOfWeek()
  9. getAllDaysDateBetween(Date startDate, Date endDate, DayOfWeek dayOfWeek)