java获取工作日 日历接口_节假日api接口之获取指定日期的节假日信息

获取指定日期的节假日信息

1、接口地址:http://api.goseek.cn/Tools/holiday?date=数字日期

2、返回数据:

05ccb5783f65

3、节假日数据说明:本接口包含2017年起的中国法定节假日数据,数据来源国务院发布的公告,每年更新1次,确保数据最新

4、示例:

返回数据:

{"code":10001,"data":2}

package com.anyierp.util;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

import java.text.SimpleDateFormat;

import net.sf.json.JSONObject;

/**

* 调用API接口判断日期是否是工作日 周末还是节假日

*

* @author i

*

*/

public class HolidayUtil {

/**

* @param urlAll

*            :请求接口

* @param httpArg

*            :参数

* @return 返回结果

*/

public static int request( String httpArg) {

String httpUrl="http://api.goseek.cn/Tools/holiday";

BufferedReader reader = null;

String result = null;

StringBuffer sbf = new StringBuffer();

httpUrl = httpUrl + "?date=" + httpArg;

int d=0;

try {

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();

JSONObject ob= JSONObject.fromObject(result);

if(ob!=null){

d=Integer.parseInt(ob.getString("data"));

}

} catch (Exception e) {

e.printStackTrace();

}

return d;

}

public static void main(String[] args) {

//判断今天是否是工作日 周末 还是节假日

SimpleDateFormat f=new SimpleDateFormat("yyyyMMdd");

String httpArg="20180811";//f.format(new Date());

System.out.println(httpArg);

int n = request(httpArg);

System.out.println(n);

}

}


版权声明:本文为weixin_35512156原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。