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<String,Object> map=new HashMap<String, Object>();
    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 


 

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值