Java Day of Week getSeqWeek(String date)

Here you can find the source of getSeqWeek(String date)

Description

get Seq Week

License

Open Source License

Declaration

public static String getSeqWeek(String date) 

Method Source Code


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

public class Main {
    public static String getSeqWeek(String date) {
        int seqWeek = 0;
        int curDate = getDate(date);
        int[][] month = getMonthDays(date);

        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 7; j++) {
                if (month[i][j] != 0) {
                    if (month[i][j] == curDate)
                        seqWeek = i + 1;
                }/*from ww  w  .  ja v a 2  s.  c o  m*/
            }
        }
        switch (seqWeek) {
        case 1:
            return "()";
        case 2:
            return "()";
        case 3:
            return "()";
        case 4:
            return "()";
        case 5:
            return "()";
        case 6:
            return "()";
        default:
            return "";
        }
    }

    public static int getDate(String date) {
        return Integer.parseInt(date.substring(6, 8));
    }

    public static int[][] getMonthDays(String date) {
        int[][] months = new int[6][7];
        int days = 1;

        int year = getYear(date);
        int month = getMonth(date);
        int day = getDate(date);

        for (int i = getFirstDayOfWeek(year, month); i < 7; i++) {
            months[0][i] = days;
            days++;
        }

        for (int i = 1; i < 6; i++) {
            for (int j = 0; j < 7; j++) {
                if (days <= LastDateInMonth(year, month, day)) {
                    months[i][j] = days;
                    days++;
                } else
                    break;
            }
        }

        return months;
    }

    public static int getYear(String date) {
        return Integer.parseInt(date.substring(0, 4));
    }

    public static int getMonth(String date) {
        return Integer.parseInt(date.substring(4, 6));
    }

    public static int getFirstDayOfWeek(int _year, int _month) {
        Calendar tmpCal = Calendar.getInstance();
        tmpCal.set(_year, _month - 1, 1);

        return (tmpCal.get(Calendar.DAY_OF_WEEK) - 1);
    }

    public static int LastDateInMonth(int _year, int _month, int _day) {
        Calendar tmpCal = Calendar.getInstance();
        tmpCal.set(Calendar.YEAR, _year);
        tmpCal.set(Calendar.MONTH, _month);
        tmpCal.set(Calendar.DATE, 0);

        return (tmpCal.get(Calendar.DATE));
    }
}

Related

  1. getNextClosestDateTime(DayOfWeek[] daysOfWeek, int hour, int min)
  2. getNextDay(long date, int startOfWeek)
  3. getNextWeekDay(Date startDate, int day)
  4. getSatDayOfWeek(Date date)
  5. getScheduledDate(int dayOfWeek, int hourOfDay, int minute, int second)
  6. getSeqWeekByMonth(Date currDate)
  7. getStartDate(int year, int week)
  8. getStartDates(Date baseDate, int weekNum)
  9. getSundayDate(int week, int year)