轉(zhuǎn):http://www.reibang.com/p/05ccb5783f65
轉(zhuǎn):http://www.reibang.com/p/99931a7a4f0d
獲取指定日期的節(jié)假日信息: http://api.goseek.cn/
package com.juqitech.zb.common.util;
import net.sf.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
/**
* 調(diào)用API接口判斷日期是否是工作日 周末還是節(jié)假日
* 工作日對應(yīng)結(jié)果為 0, 休息日對應(yīng)結(jié)果為 1, 節(jié)假日對應(yīng)的結(jié)果為 2
*/
public class HolidayUtil {
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;//工作日對應(yīng)結(jié)果為 0, 休息日對應(yīng)結(jié)果為 1, 節(jié)假日對應(yīng)的結(jié)果為 2
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) {
//判斷今天是否是工作日 周末 還是節(jié)假日
SimpleDateFormat f=new SimpleDateFormat("yyyyMMdd");
String httpArg="20190216";//f.format(new Date());
System.out.println(httpArg);
int n = request(httpArg);
System.out.println(n);
//工作日對應(yīng)結(jié)果為 0, 休息日對應(yīng)結(jié)果為 1, 節(jié)假日對應(yīng)的結(jié)果為 2
}
}