百度的接口没有更新2021年节假日 ,文章下方再补一个第三方接口
百度日历Json接口
只能解析当年及以前年份的节假日,因为下一年的节假日需要等国务院发布节假日,想要实时获取,可以自定义定时任务每年的第一天去查询百度的接口https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=2020&resource_id=6018&format=json
数据中的状态是2 做了下判断 只有1的状态是节假日
根据年份解析百度接口的节假日,然后封装到集合中
public static Map<Date, DayStatusEnum> holidayByList(String year){
String httpUrl = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query="+year+"&resource_id=6018&format=json";
BufferedReader reader = null;
String result = null;
StringBuffer sbf = new StringBuffer();
Map<Date,DayStatusEnum> dateMap = new HashMap<Date,DayStatusEnum>();
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.