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

来源:互联网 发布:freehand 11 for mac 编辑:程序博客网 时间:2024/05/22 00:10
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;    }
传入一个工作日天数,得到一个该天数工作日后的时间
                                             
0 0
原创粉丝点击