Java Weekend isEndOfWeek()

Here you can find the source of isEndOfWeek()

Description

is End Of Week

License

Open Source License

Declaration

public static boolean isEndOfWeek() 

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;

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

    public static boolean isEndOfWeek() {
        return getWeekNumByDate(getCurrentDate_String()) == 0;
    }//from w  w w .j  a  v a  2s .com

    public static int getWeekNumByDate(String date) {
        SimpleDateFormat format = new SimpleDateFormat(DF_YMD);
        try {
            Date d = format.parse(date);
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            int num = cal.get(Calendar.DAY_OF_WEEK) - 1;
            return num;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static String getCurrentDate_String() {
        return dateToString(now(), DF_YMD);
    }

    public static String dateToString(Date date, String format) {
        if (date == null) {
            return "";
        }
        synchronized (date) {
            SimpleDateFormat df = new SimpleDateFormat(format);
            return df.format(date);
        }
    }

    public static String dateToString(Date date) {
        return dateToString(date, DF_YMD);
    }

    public static Date now() {
        return new Date();
    }
}

Related

  1. endOfWeek(Date date, String format)
  2. getCalendarWeekOfDate(Date date)
  3. getCurWeekEnd(String strDate)
  4. getWeekRange(String strBeginDate, String strEndDate, String pattern)
  5. isWeekend(Calendar calendar)
  6. isWeekend(Calendar dateCal)
  7. isWeekend(Date date)
  8. isWeekend(Date date)