判断当前日期是否为法定节假日(API接口调用)

package com.mln.wateroa.common;


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import net.sf.json.JSONObject;


public class DateUtil {
/**
* @param urlAll :请求接口实例 //http://timor.tech/api/holiday/info/2021-06-16 也可以
* @param httpArg :日期参数yyyy-MM-dd
* @return 返回结果如下  {"code":0,"type":{"type":0,"name":"周三","week":3},"holiday":null}

*/
public JSONObject request( String httpArg) {
BufferedReader reader = null;
String result = null;
JSONObject jsonObjectResult = null;
StringBuffer sbf = new StringBuffer();
String httpUrl = "免费节假日API_原百度节假日API=" + httpArg;

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();
jsonObjectResult = JSONObject.fromObject(result);//转为JSONObject对象
} catch (Exception e) {
e.printStackTrace();
}
return jsonObjectResult;
}
public static void main(String[] args) {
JSONObject a = new DateUtil().request("20180101");
    System.out.println(a);
}
}

你可能感兴趣的:(java,java)