200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > java获取工作日 日历接口_节假日api接口之获取指定日期的节假日信息

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

时间:2020-07-25 00:31:56

相关推荐

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

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

1、接口地址:/Tools/holiday?date=数字日期

2、返回数据:

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

4、示例:

返回数据:

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

package com.anyierp.util;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import .HttpURLConnection;

import .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="/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="0811";//f.format(new Date());

System.out.println(httpArg);

int n = request(httpArg);

System.out.println(n);

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。