Java Weekend isWeekend(String datestr)

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

Description

is Weekend

License

Open Source License

Declaration

public static boolean isWeekend(String datestr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;

import java.text.SimpleDateFormat;

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

public class Main {

    public static boolean isWeekend(String datestr) {
        if (datestr == null || "".equals(datestr.trim())) {
            return false;
        }/*from   w w w  .  ja va 2 s.  co  m*/
        SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = myFormatter.parse(datestr);
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(date);
            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
                    || calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                return true;
            }
        } catch (ParseException e) {
            return false;
        }
        return false;
    }
}

Related

  1. isWeekEnd(Date datum)
  2. IsWeekEnd(GregorianCalendar aInCal)
  3. isWeekend(String date)
  4. isWeekend(String date)
  5. isWeekend(String date)
  6. isWeekend(String dateStr)
  7. isWeekends(String date, String pattern)