Java Week Day getWeekDay(int weekday)

Here you can find the source of getWeekDay(int weekday)

Description

get Week Day

License

Apache License

Parameter

Parameter Description
date a parameter

Exception

Parameter Description
ParseException an exception

Declaration





























public static int getWeekDay(int weekday) 

Method Source Code

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

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

public class Main {
    /**//  w  w  w. j  av a  2 s  . co  m
     * 
     * @param date
     * @return
     * @throws ParseException
     */
    // public static long getLongDate(Date date) {
    // Calendar calendar = Calendar.getInstance();
    //      
    // calendar.setTime(date);
    //      
    // /************************************************************************
    // * + + + + + + + + + *
    // * 0 8 16 24 32 40 48 56 64 *
    // * +-------+-------+-------+-------+-------+-------+-------+-------+ *
    // * + year +month +day +hour +minute +seconds+ + *
    // * +-------+-------+-------+-------+-------+-------+-------+-------+ *
    // ************************************************************************/
    //      
    // // 0xFFFFFFFFFFFFFFFFL
    // // 0x00FFFFFFFFFFFFFFL
    // // 0x0000FFFFFFFFFFFFL
    // // 0x000000FFFFFFFFFFL
    // // 0x00000000FFFFFFFFL
    // // 0x0000000000FFFFFFL
    // // 0x000000000000FFFFL
    // // 0x00000000000000FFL
    //      
    // long year = calendar.get( Calendar.YEAR );
    // long month = calendar.get( Calendar.MONTH );
    // long day = calendar.get( Calendar.DAY_OF_MONTH );
    // long hour = calendar.get( Calendar.HOUR_OF_DAY );
    // long minute = calendar.get( Calendar.MINUTE );
    // long seconds = calendar.get( Calendar.SECOND );
    //      
    // long result = 0;
    //      
    // return result;
    // }

    public static int getWeekDay(int weekday) {

        if (weekday == 1) {
            return Calendar.MONDAY;
        } else if (weekday == 2) {
            return Calendar.TUESDAY;
        } else if (weekday == 3) {
            return Calendar.WEDNESDAY;
        } else if (weekday == 4) {
            return Calendar.THURSDAY;
        } else if (weekday == 5) {
            return Calendar.FRIDAY;
        } else if (weekday == 6) {
            return Calendar.SATURDAY;
        } else if (weekday == 7) {
            return Calendar.SUNDAY;
        }

        return -1;
    }

    public static Date getWeekDay(Date date, int weekday) {
        Calendar strDate = Calendar.getInstance();
        strDate.setFirstDayOfWeek(Calendar.MONTH);
        strDate.setTime(date);
        strDate.set(Calendar.DAY_OF_WEEK, weekday);
        return strDate.getTime();
    }
}

Related

  1. GetWeekDay()
  2. getWeekDay()
  3. getWeekday(Date date)
  4. getWeekDay(Date date)
  5. getWeekDay(Date dt, int weekDay)
  6. getWeekDay(String date)
  7. getWeekday(String date)
  8. getWeekDay(String dateString, int weekDay)
  9. getWeekDay(String str)