Java Day of Week isMatchWeek(Date date, int week)

Here you can find the source of isMatchWeek(Date date, int week)

Description

is Match Week

License

Open Source License

Declaration

public static boolean isMatchWeek(Date date, int week) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2005, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/* ww  w  .  j  av a  2s.c  o  m*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

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

public class Main {

    public static boolean isMatchWeek(Date date, int week) {
        return getWeekOfDate(date) == week;
    }

    public static boolean isMatchWeek(Date date, Integer[] weeks) {

        int len = weeks.length;

        for (int m = 0; m < len; m++) {

            int week = weeks[m];

            if (isMatchWeek(date, week))
                return true;
        }

        return false;
    }

    public static int getWeekOfDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return (calendar.get(Calendar.DAY_OF_WEEK) - 1) == 0 ? 7 : calendar.get(Calendar.DAY_OF_WEEK) - 1;
    }
}

Related

  1. getWeekStart(Date date)
  2. getWeekStartDateBeforeCurrent(int weekNum, Date current)
  3. getWeekth(String sDate)
  4. getYearOfWeek(Date date)
  5. incWeek(java.util.Date date, int amount, Locale locale)
  6. isOnWeekend(Date date)
  7. isSameWeekDates(Date date1, Date date2)
  8. isWeekday(Date startDate)
  9. isWeekDay(final Date date)