Java Day of Week getDayOfWeek(int year, int month, int day)

Here you can find the source of getDayOfWeek(int year, int month, int day)

Description

get Day Of Week

License

Open Source License

Declaration

public static int[] getDayOfWeek(int year, int month, int day) 

Method Source Code


//package com.java2s;
import java.util.Calendar;

public class Main {

    public static int[] getDayOfWeek(int year, int month, int day) {
        int[] rtn = new int[6];
        int week = 0;
        long longDate = 0;

        java.util.Date date = null;
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();

        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, day);
        calendar.setFirstDayOfWeek(Calendar.SUNDAY);

        week = calendar.get(Calendar.DAY_OF_WEEK);
        longDate = (calendar.getTime()).getTime() - (60 * 1000 * 60 * 24 * (week - 1));
        date = new java.util.Date(longDate);
        calendar1.setTime(date);//w  ww. jav a2 s.  com

        rtn[0] = calendar1.get(Calendar.YEAR);
        rtn[1] = calendar1.get(Calendar.MONTH) + 1;
        rtn[2] = calendar1.get(Calendar.DATE);

        longDate = (calendar.getTime()).getTime() + (60 * 1000 * 60 * 24 * (7 - week));
        date = new java.util.Date(longDate);
        calendar2.setTime(date);
        rtn[3] = calendar2.get(Calendar.YEAR);
        rtn[4] = calendar2.get(Calendar.MONTH) + 1;
        rtn[5] = calendar2.get(Calendar.DATE);

        return rtn;
    }
}

Related

  1. getDay(long date, int startOfWeek, int increment)
  2. getDayAfterGivenDate(Date date, int dayOfWeek)
  3. getDayOfWeek()
  4. getDayOfWeek(Date date)
  5. getDayOfWeek(int _year, int _month, int _day)
  6. getDayOfWeek(int year, int month, int day)
  7. getDayOfWeek(String date, String pattern)
  8. getDayOfWeek(String datetime)
  9. getDayOfWeek(String f)