Java Week Day isWeekday(String dateStr, String format)

Here you can find the source of isWeekday(String dateStr, String format)

Description

is Weekday

License

Open Source License

Declaration

public static boolean isWeekday(String dateStr, String format) 

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.TimeZone;

public class Main {
    static public final String FORMAT_NORMAL = "yyyy-MM-dd HH:mm:ss";

    public static boolean isWeekday(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);/*from   www.  j  a  v a2s.com*/
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return w > 0 && w < 6;
    }

    public static boolean isWeekday(String dateStr, String format) {
        Date date = parse(dateStr, format);
        return date != null && isWeekday(date);
    }

    public static boolean isWeekday(String dateStr) {
        return isWeekday(dateStr, FORMAT_NORMAL);
    }

    public static Date parse(String str, String format) {
        try {
            SimpleDateFormat sf = new SimpleDateFormat(format);
            sf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
            return sf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. getWeekFirstDay(Date date)
  2. isDayOfWeek(int day)
  3. isDayOfWeek(String str, int dayOfWeek)
  4. isFirseDayOfCurrentWeek(Date date)
  5. isoDayOfWeek(int javaDayOfWeek)
  6. isWeekendDay(String strDay, DateFormat dateFormatter)
  7. isWeekendToday()
  8. lastDayOfWeek(int year, int month)
  9. nextDayAndHour(int dayOfTheWeek, int hour)