Java Week Day isWeekendDay(String strDay, DateFormat dateFormatter)

Here you can find the source of isWeekendDay(String strDay, DateFormat dateFormatter)

Description

Determines if a day is a day of the weekend, i.e., Saturday or Sunday

License

Open Source License

Parameter

Parameter Description
strDay Given Date.
dateFormatter Format of the date.

Return

true if the date is a Sunday or a Saturday.

Declaration

public static boolean isWeekendDay(String strDay,
        DateFormat dateFormatter) throws ParseException 

Method Source Code

//package com.java2s;
/*/*  w  ww.  ja  v a 2  s.  c o m*/
 *************************************************************************
 * The contents of this file are subject to the Openbravo  Public  License
 * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
 * Version 1.1  with a permitted attribution clause; you may not  use this
 * file except in compliance with the License. You  may  obtain  a copy of
 * the License at http://www.openbravo.com/legal/license.html 
 * Software distributed under the License  is  distributed  on  an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific  language  governing  rights  and  limitations
 * under the License. 
 * The Original Code is Openbravo ERP. 
 * The Initial Developer of the Original Code is Openbravo SLU 
 * All portions are Copyright (C) 2012-2015 Openbravo SLU
 * All Rights Reserved. 
 * Contributor(s):  ______________________________________.
 ************************************************************************
 */

import java.text.DateFormat;
import java.text.ParseException;

import java.util.Calendar;

public class Main {
    /**
     * Determines if a day is a day of the weekend, i.e., Saturday or Sunday
     * 
     * @param strDay
     *          Given Date.
     * @param dateFormatter
     *          Format of the date.
     * @return true if the date is a Sunday or a Saturday.
     */
    public static boolean isWeekendDay(String strDay,
            DateFormat dateFormatter) throws ParseException {
        final Calendar Day = Calendar.getInstance();
        Day.setTime(dateFormatter.parse(strDay));
        final int weekday = Day.get(Calendar.DAY_OF_WEEK);
        // Gets the number of the day of the week: 1-Sunday, 2-Monday, 3-Tuesday, 4-Wednesday,
        // 5-Thursday, 6-Friday, 7-Saturday
        return weekday == 1 || weekday == 7;
    }
}

Related

  1. isDayOfWeek(int day)
  2. isDayOfWeek(String str, int dayOfWeek)
  3. isFirseDayOfCurrentWeek(Date date)
  4. isoDayOfWeek(int javaDayOfWeek)
  5. isWeekday(String dateStr, String format)
  6. isWeekendToday()
  7. lastDayOfWeek(int year, int month)
  8. nextDayAndHour(int dayOfTheWeek, int hour)
  9. nextTwoWeeksFromToday()