Java 判断日期是否为工作日

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

    //判断日期是否是工作日(0 上班 1周末 2节假日)

    SimpleDateFormat f=new SimpleDateFormat("yyyyMMdd");

    String httpArg=f.format(projectCost.getBizDate());

    String jsonResult = request(httpArg);

    JSONObject json=new JSONObject(jsonResult);

    Map map=new HashMap();

    Iterator iterator = json.keys();

    while (iterator.hasNext()) {

        String key = (String)iterator.next();

        Object value = json.get(key);

        map.put(key, value);

    }

    if("0".equals(map.get(httpArg))){

        projectCost.setIsWeek("0");

    }else{

        projectCost.setIsWeek("1");

    }

    /**

     * 判断日期是否是工作日(0 上班 1周末 2节假日)

     * @param httpArg 日期

     * @return

     * @author ztf

     * @date 2017年11月15日 下午2:46:00

     */

    public static String request(String httpArg) {

        String result = null;

        try {

            String httpUrl="http://www.easybots.cn/api/holiday.php";

            BufferedReader reader = null;

            StringBuffer sbf = new StringBuffer();

            httpUrl = httpUrl + "?d=" + httpArg +"&ak=k402.fa60b4d3a640095bc729603064357c14@itopview.com";

            URL url = new URL(httpUrl);

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            connection.setRequestMethod("GET");

            connection.connect();

            InputStream is = connection.getInputStream();

            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));

            String strRead = null;

            while ((strRead = reader.readLine()) != null) {

                sbf.append(strRead);

                sbf.append("\r\n");

            }

            reader.close();

            result = sbf.toString();

        } catch (Exception e) {

            e.printStackTrace();

        }

        return result;

    }

    

    用法举例

        检查一个日期是否为节假日 http://www.easybots.cn/api/holiday.php?d=20130101

        检查多个日期是否为节假日 http://www.easybots.cn/api/holiday.php?d=20130101,20130103,20130105,20130201

        获取2012年1月份节假日 http://www.easybots.cn/api/holiday.php?m=201201

        获取2013年1/2月份节假日 http://www.easybots.cn/api/holiday.php?m=201301,201302

    

    参考网站:http://www.zuidaima.com/share/3037907365252096.htm 

    授权申请:http://www.easybots.cn/holiday_api-apply.net