百度API获取某个工作日之后的时间

http://apistore.baidu.com/apiworks/servicedetail/1116.html   百度节假日shJSON返回示例 :
{"20130101":2,"20130103":2,"20130105":"0","20130201":"0"}
备注 :
功能特点
检查具体日期是否为节假日,工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2;
(对应支付工资比例分别为 100%, 200% 和 300%,以方便程序计算 计算方法: 基本工资* (1+结果数值))
获取具体月份下的节假日情况,只返回休息日或者节假日数据;
可同时传递一个或者多个日期(月份);
支持 2009 年起至2016年 中国法定节假日,以国务院发布的公告为准,随时调整及增加;http://www.gov.cn/zfwj/bgtfd.htm或http://www.gov.cn/zhengce/xxgkzl.htm
参数可以以 GET 或 POST 方式传递,以 JSON 格式返回结果。

用法举例
检查一个日期是否为节假日 ?d=20160101
检查多个日期是否为节假日 ?d=20160101,20160103,20160105,20161201
获取2016年10月份节假日 ?d=201610
获取2016年所有节假日 ?d=2016
获取2016年1/2月份节假日 ?d=201601,201602
String httpUrl = "http://apis.baidu.com/xiaogg/holiday/holiday";
    String httpArg = "d=20151001";
    String jsonResult = getHolidays(httpUrl, httpArg);
    static String apikey = "apikey";

    public static String getHolidays(String httpUrl, String httpArg) {
        BufferedReader reader = null;
        String result = null;
        StringBuffer sbf = new StringBuffer();
        httpUrl = httpUrl + "?" + httpArg;

        try {
            URL url = new URL(httpUrl);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("GET");

            connection.setRequestProperty("apikey", apikey);
            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;
    }
</pre><pre name="code" class="java"> public static Date getEndDay(int x) {
        Date date;
        if (x==0){
            return new Date();
        }
        String dateStr = "d=";
        for (int i = 0; i < 14; i++) {
            date = new Date() + i;
            dateStr += DateUtil.dateToStr(date) + ",";

        }
        String httpUrl = "http://apis.baidu.com/xiaogg/holiday/holiday";
        //String httpArg = "";

        JsonSlurper jsonSlurper = new JsonSlurper()
        def json = jsonSlurper.parseText(DateUtil.getHolidays(httpUrl, dateStr))
        int count = 0;
        date = new Date()
        for (int i = 0; i < json.size(); i++) {

            if (json.getAt(DateUtil.dateToStr(date)).equals("0")) {
                count++
                if (count == x) {
                    break
                }
            }
            date += 1;
        }
        return date;
    }
传入一个工作日天数,得到一个该天数工作日后的时间

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值