Java Weekend isWeekend(String date)

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

Description

is Weekend

License

Open Source License

Declaration

public static boolean isWeekend(String date) 

Method Source Code


//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static final String dateFormat = "yyyy-MM-dd";

    public static boolean isWeekend(String date) {
        Calendar cal = Calendar.getInstance();
        Date d = strToDtSimpleFormat(date);
        cal.setTime(d);//w  ww . ja  v a  2  s . co m
        int day = cal.get(Calendar.DAY_OF_WEEK);
        if (day == Calendar.SUNDAY || day == Calendar.SATURDAY) {
            return true;
        }

        return false;
    }

    public static final Date strToDtSimpleFormat(String strDate) {
        if (strDate == null) {
            return null;
        }

        try {
            return getFormat(dateFormat).parse(strDate);
        } catch (Exception e) {
        }

        return null;
    }

    public static final DateFormat getFormat(String format) {
        return new SimpleDateFormat(format);
    }
}

Related

  1. isWeekend(Calendar dateCal)
  2. isWeekend(Date date)
  3. isWeekend(Date date)
  4. isWeekEnd(Date datum)
  5. IsWeekEnd(GregorianCalendar aInCal)
  6. isWeekend(String date)
  7. isWeekend(String date)
  8. isWeekend(String dateStr)
  9. isWeekend(String datestr)