获取全年所有节假日非工作日

已更新节假日2021、2020、2019

一、项目简介地址

本文的节假日特指非工作日,非工作日=[ 周末 + 节假日 -(被调成工作日的日期)]
本项目主要功能是获取全年的节假日,获取2021 / 2020 / 2019年节假日的工具类,网上第三方获取节假日的接口api不稳定,经常失效,建议落地到本地数据库去使用。原因较多

  • 避免第三方接口失效或者被改动
  • 落地到数据库之后调用速度快
  • 可定制,很多公司跟法定的节假日还是时不时有出入的,比如突然某天就团建或者补班,遇台风休息等

github项目地址:https://github.com/lufei222/san-holiday.git

二、节假日查询

百度搜索节假日,官方参考国务院放假地址
http://www.gov.cn/zhengce/content/2019-11/21/content_5454164.htm
在这里插入图片描述

三、节假日数据获取

方式一:调用api查询

2020年及之前的年份才能用此api,2021年的暂时只能手动百度

首先查询百度万年历节接口(其中包含全年节假日数据),得到json数据 (全年节假日信息在json的holiday中,query=2020,其实默认就是202001,其他月份的万年历请求如query=202004)


请求的api:

https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=2020&resource_id=6018

返回的json内容如下,
json预览图:
在这里插入图片描述
json数据:

{"status":"0","t":"","set_cache_time":"","data":[{"StdStg":6018,"StdStl":8,"_update_time":"1580102250","cambrian_appid":"0","almanac":[{"avoid":"诸事不宜.","date":"2020-1-1","suit":"平治道涂.余事勿取."},{"avoid":"开市.嫁娶.","date":"2020-1-2","suit":"求嗣.斋醮.塑绘.订盟.纳采.出火.拆卸.修造.动土.造桥.安机械.栽种.纳畜.牧养.入殓.除服.成服.移柩.破土.安葬."},{"avoid":"开市.安葬.","date":"2020-1-3","suit":"嫁娶.订盟.纳采.祭祀.祈福.修造.动土.移徙.入宅."},{"avoid":"诸事不宜.","date":"2020-1-4","suit":"治病.破屋.坏垣.余事勿取."},{"avoid":"造桥.安门.理发.造庙.栽种.作灶.","date":"2020-1-5","suit":"祭祀.祈福.求嗣.斋醮.开光.入学.订盟.冠笄.伐木.修造.动土.起基.放水.交易.开池."},{"avoid":"祈福.嫁娶.安床.入宅.造船.","date":"2020-1-6","suit":"沐浴.开仓.出货财.开市.交易.立券.纳财.栽种.纳畜.牧养.畋猎.入殓.破土.安葬."},{"avoid":"造庙.入宅.修造.安葬.行丧.嫁娶.","date":"2020-1-7","suit":"祭祀.沐浴.补垣.塞穴.断蚁.解除.余事勿取."},{"avoid":"开市.安床.安葬.修坟.","date":"2020-1-8","suit":"嫁娶.纳采.订盟.问名.祭祀.冠笄.裁衣.会亲友.进人口.纳财.捕捉.作灶."},{"avoid":"造庙.嫁娶.出行.动土.安葬.行丧.","date":"2020-1-9","suit":"订盟.纳采.会亲友.祭祀.斋醮.沐浴.塑绘.出火.开光.竖柱.上梁.开市.交易.立券.作梁.开柱眼.伐木.架马.安门.安床.拆卸.牧养.造畜椆栖.掘井."},{"avoid":"开光.嫁娶.开市.动土.破土.","date":"2020-1-10","suit":"交易.立券.纳财.安床.裁衣.造畜椆栖.安葬.谢土.启攒.除服.成服.修坟.立碑.移柩.入殓."},{"avoid":"破土.动土.安葬.","date":"2020-1-11","suit":"祭祀.解除.教牛马.会亲友.余事勿取."},{"avoid":"探病.祭祀.出行.上梁.造屋.谢土.安葬.","date":"2020-1-12","suit":"纳采.订盟.移徙.纳财.开市.交易.立券.入宅.会亲友.解除.求医.治病.入学.安床.安门.安香.出火.拆卸.扫舍.入宅.挂匾.开生坟.合寿木.破土.修坟.启攒.入殓."},{"avoid":"入宅.开光.开市.动土.","date":"2020-1-13","suit":"嫁娶.订盟.纳采.祭祀.祈福.求嗣.会亲友.解除.出行.入学.纳财.开市.交易.立券.习艺.经络.安床.开仓.出货财.纳畜.安葬.启攒.修坟.入殓."},{"avoid":"移徙.入宅.造庙.作灶.治病.安葬.","date":"2020-1-14","suit":"祭祀.冠笄.嫁娶.会亲友.进人口.裁衣.结网.平治道涂."},{"avoid":"嫁娶.安葬.","date":"2020-1-15","suit":"祭祀.安碓硙.结网.余事勿取."},{"avoid":"造屋.开市.动土.破土.","date":"2020-1-16","suit":"嫁娶.祭祀.沐浴.裁衣.出行.理发.移徙.捕捉.畋猎.放水.入宅.除服.成服.启攒.安葬.移柩.入殓."},{"avoid":"嫁娶.开市.安葬.","date":"2020-1-17","suit":"破屋.坏垣.余事勿取."},{"avoid":"祈福.嫁娶.造庙.安床.谢土.","date":"2020-1-18","suit":"纳采.订盟.祭祀.求嗣.出火.塑绘.裁衣.会亲友.入学.拆卸.扫舍.造仓.挂匾.掘井.开池.结网.栽种.纳畜.破土.修坟.立碑.安葬.入殓."},{"avoid":"开市.伐木.嫁娶.作梁.","date":"2020-1-19","suit":"入殓.除服.成服.移柩.启攒.安葬.修坟.立碑."},{"avoid":"开市.安床.","date":"2020-1-20","suit":"祭祀.作灶.入殓.除服.余事勿取."},{"avoid":"嫁娶.入殓.安葬.出行.","date":"2020-1-21","suit":"塑绘.开光.沐浴.冠笄.会亲友.作灶.放水.造畜椆栖."},{"avoid":"开仓.嫁娶.移徙.入宅.","date":"2020-1-22","suit":"祭祀.沐浴.祈福.斋醮.订盟.纳采.裁衣.拆卸.起基.竖柱.上梁.安床.入殓.除服.成服.移柩.启攒.挂匾.求嗣.出行.合帐.造畜椆栖."},{"avoid":"诸事不宜.","date":"2020-1-23","suit":"祭祀.解除.余事勿取."},{"avoid":"作灶.祭祀.上梁.出行.","date":"2020-1-24","suit":"沐浴.解除.订盟.纳采.裁衣.冠笄.拆卸.修造.动土.移徙.入宅.除服.成服.移柩.破土.启攒.安葬.扫舍.修坟.伐木.纳财.交易.立券."},{"avoid":"作灶.掘井.谢土.入宅.","date":"2020-1-25","suit":"出行.嫁娶.订盟.纳采.入殓.安床.启攒.安葬.祭祀.裁衣.会亲友.进人口."},{"avoid":"嫁娶.移徙.入宅.开光.","date":"2020-1-26","suit":"修饰垣墙.平治道涂.入殓.移柩.余事勿取."},{"avoid":"出行.治病.安葬.开市.","date":"2020-1-27","suit":"会亲友.纳采.进人口.修造.动土.竖柱.上梁.祭祀.开光.塑绘.祈福.斋醮.嫁娶.安床.移徙.入宅.安香.纳畜."},{"avoid":"造屋.开市.作灶.入宅.","date":"2020-1-28","suit":"祭祀.会亲友.出行.订盟.纳采.沐浴.修造.动土.祈福.斋醮.嫁娶.拆卸.安床.入殓.移柩.安葬.谢土.赴任.裁衣.竖柱.上梁.伐木.捕捉.栽种.破土.安门."},{"avoid":"诸事不宜.","date":"2020-1-29","suit":"解除.破屋.坏垣.余事勿取."},{"avoid":"入宅.安床.","date":"2020-1-30","suit":"塑绘.开光.出行.订盟.纳采.除服.成服.嫁娶.纳婿.入殓.移柩.启攒.安葬.立碑."},{"avoid":"破土.伐木.","date":"2020-1-31","suit":"入殓.除服.成服.移柩.启攒.安葬.立碑.余事勿取."}],"holiday":[{"desc":"1月1日放假一天","festival":"2020-1-1","list":[{"date":"2020-1-1","status":"1"}],"list#num#baidu":1,"name":"元旦","rest":"2019年12月30日和2019年12月31日请假两天,与周末连休可拼5天小长假。"},{"desc":"1月24日放假一天","festival":"2020-1-24","list":[{"date":"2020-1-24","status":"1"}],"list#num#baidu":1,"name":"除夕","rest":"农历腊月最后一天为除夕,即大年初一前夜,又称为年三十。"},{"desc":"1月24日(除夕)至1月30日放假7天,1月19日,2月1日上班","festival":"2020-1-25","list":[{"date":"2020-1-24","status":"1"},{"date":"2020-1-25","status":"1"},{"date":"2020-1-26","status":"1"},{"date":"2020-1-27","status":"1"},{"date":"2020-1-28","status":"1"},{"date":"2020-1-29","status":"1"},{"date":"2020-1-30","status":"1"},{"date":"2020-1-19","status":"2"},{"date":"2020-1-31","status":"1"},{"date":"2020-2-1","status":"1"},{"date":"2020-2-2","status":"1"}],"list#num#baidu":11,"name":"春节","rest":"2020年1月19日至2020年1月23日请假5天,与周末连休可拼13天长假。"},{"desc":"4月4日至4月6日放假3天","festival":"2020-4-4","list":[{"date":"2020-4-4","status":"1"},{"date":"2020-4-5","status":"1"},{"date":"2020-4-6","status":"1"}],"list#num#baidu":3,"name":"清明节","rest":"2020年4月7日至2020年4月10日请假4天,与周末连休可拼9天长假。"},{"desc":"5月1日至5月5日放假5天,4月26日,5月9日上班","festival":"2020-5-1","list":[{"date":"2020-5-1","status":"1"},{"date":"2020-5-2","status":"1"},{"date":"2020-5-3","status":"1"},{"date":"2020-5-4","status":"1"},{"date":"2020-5-5","status":"1"},{"date":"2020-4-26","status":"2"},{"date":"2020-5-9","status":"2"}],"list#num#baidu":7,"name":"劳动节","rest":"2020年4月26日至2020年4月30日请假5天,与周末连休可拼11天长假。"},{"desc":"6月25日至6月27日放假3天,6月28日上班","festival":"2020-6-25","list":[{"date":"2020-6-25","status":"1"},{"date":"2020-6-26","status":"1"},{"date":"2020-6-27","status":"1"},{"date":"2020-6-28","status":"2"}],"list#num#baidu":4,"name":"端午节","rest":"2020年6月22日至2020年6月24日请假3天,与周末连休可拼8天长假。"},{"desc":"10月1日至10月8日放假8天,9月27日,10月10日上班","festival":"2020-10-1","list":[{"date":"2020-10-1","status":"1"},{"date":"2020-10-2","status":"1"},{"date":"2020-10-3","status":"1"},{"date":"2020-10-4","status":"1"},{"date":"2020-10-5","status":"1"},{"date":"2020-10-6","status":"1"},{"date":"2020-10-7","status":"1"},{"date":"2020-10-8","status":"1"},{"date":"2020-9-27","status":"2"},{"date":"2020-10-10","status":"2"}],"list#num#baidu":10,"name":"中秋节","rest":"10月9日至10月10日请假2天,与周末连休可拼11天长假。"},{"desc":"10月1日至10月8日放假8天,9月27日,10月10日上班","festival":"2020-10-1","list":[{"date":"2020-10-1","status":"1"},{"date":"2020-10-2","status":"1"},{"date":"2020-10-3","status":"1"},{"date":"2020-10-4","status":"1"},{"date":"2020-10-5","status":"1"},{"date":"2020-10-6","status":"1"},{"date":"2020-10-7","status":"1"},{"date":"2020-10-8","status":"1"},{"date":"2020-9-27","status":"2"},{"date":"2020-10-10","status":"2"}],"list#num#baidu":10,"name":"国庆节","rest":"10月9日至10月10日请假2天,与周末连休可拼11天长假。"}],"holidaylist":[{"name":"元旦","startday":"2020-1-1"},{"name":"除夕","startday":"2020-1-24"},{"name":"春节","startday":"2020-1-25"},{"name":"清明节","startday":"2020-4-4"},{"name":"劳动节","startday":"2020-5-1"},{"name":"端午节","startday":"2020-6-25"},{"name":"中秋节","startday":"2020-10-1"},{"name":"国庆节","startday":"2020-10-1"}],"key":"2020年1月1日","selectday":"2020-1-1","url":"http:\/\/nourl.baidu.com\/6018","loc":"https:\/\/dss1.baidu.com\/8aQDcnSm2Q5IlBGlnYG\/q?r=2002753&k=2020%E5%B9%B41%E6%9C%881%E6%97%A5","SiteId":2002753,"_version":2767,"_select_time":1580102077,"clicklimit":"1-3","ExtendedLocation":"","OriginQuery":"2020","tplt":"calendar_new","resourceid":"6018","fetchkey":"6018_2020年1月1日","role_id":7,"disp_type":0,"appinfo":""}]}

把json复制到谷歌控制台执行js解析得到节假日

接着再浏览器控制台或者js解析json
//百度接口返回的json
var responseJson = {"status":"0","t":"","set_cache_time":"","data":[{"StdStg":6018,"StdStl":8,"_update_time":"1580102250","cambrian_appid":"0","almanac":[{"avoid":"诸事不宜.","date":"2020-1-1","suit":"平治道涂.余事勿取."},{"avoid":"开市.嫁娶.","date":"2020-1-2","suit":"求嗣.斋醮.塑绘.订盟.纳采.出火.拆卸.修造.动土.造桥.安机械.栽种.纳畜.牧养.入殓.除服.成服.移柩.破土.安葬."},{"avoid":"开市.安葬.","date":"2020-1-3","suit":"嫁娶.订盟.纳采.祭祀.祈福.修造.动土.移徙.入宅."},{"avoid":"诸事不宜.","date":"2020-1-4","suit":"治病.破屋.坏垣.余事勿取."},{"avoid":"造桥.安门.理发.造庙.栽种.作灶.","date":"2020-1-5","suit":"祭祀.祈福.求嗣.斋醮.开光.入学.订盟.冠笄.伐木.修造.动土.起基.放水.交易.开池."},{"avoid":"祈福.嫁娶.安床.入宅.造船.","date":"2020-1-6","suit":"沐浴.开仓.出货财.开市.交易.立券.纳财.栽种.纳畜.牧养.畋猎.入殓.破土.安葬."},{"avoid":"造庙.入宅.修造.安葬.行丧.嫁娶.","date":"2020-1-7","suit":"祭祀.沐浴.补垣.塞穴.断蚁.解除.余事勿取."},{"avoid":"开市.安床.安葬.修坟.","date":"2020-1-8","suit":"嫁娶.纳采.订盟.问名.祭祀.冠笄.裁衣.会亲友.进人口.纳财.捕捉.作灶."},{"avoid":"造庙.嫁娶.出行.动土.安葬.行丧.","date":"2020-1-9","suit":"订盟.纳采.会亲友.祭祀.斋醮.沐浴.塑绘.出火.开光.竖柱.上梁.开市.交易.立券.作梁.开柱眼.伐木.架马.安门.安床.拆卸.牧养.造畜椆栖.掘井."},{"avoid":"开光.嫁娶.开市.动土.破土.","date":"2020-1-10","suit":"交易.立券.纳财.安床.裁衣.造畜椆栖.安葬.谢土.启攒.除服.成服.修坟.立碑.移柩.入殓."},{"avoid":"破土.动土.安葬.","date":"2020-1-11","suit":"祭祀.解除.教牛马.会亲友.余事勿取."},{"avoid":"探病.祭祀.出行.上梁.造屋.谢土.安葬.","date":"2020-1-12","suit":"纳采.订盟.移徙.纳财.开市.交易.立券.入宅.会亲友.解除.求医.治病.入学.安床.安门.安香.出火.拆卸.扫舍.入宅.挂匾.开生坟.合寿木.破土.修坟.启攒.入殓."},{"avoid":"入宅.开光.开市.动土.","date":"2020-1-13","suit":"嫁娶.订盟.纳采.祭祀.祈福.求嗣.会亲友.解除.出行.入学.纳财.开市.交易.立券.习艺.经络.安床.开仓.出货财.纳畜.安葬.启攒.修坟.入殓."},{"avoid":"移徙.入宅.造庙.作灶.治病.安葬.","date":"2020-1-14","suit":"祭祀.冠笄.嫁娶.会亲友.进人口.裁衣.结网.平治道涂."},{"avoid":"嫁娶.安葬.","date":"2020-1-15","suit":"祭祀.安碓硙.结网.余事勿取."},{"avoid":"造屋.开市.动土.破土.","date":"2020-1-16","suit":"嫁娶.祭祀.沐浴.裁衣.出行.理发.移徙.捕捉.畋猎.放水.入宅.除服.成服.启攒.安葬.移柩.入殓."},{"avoid":"嫁娶.开市.安葬.","date":"2020-1-17","suit":"破屋.坏垣.余事勿取."},{"avoid":"祈福.嫁娶.造庙.安床.谢土.","date":"2020-1-18","suit":"纳采.订盟.祭祀.求嗣.出火.塑绘.裁衣.会亲友.入学.拆卸.扫舍.造仓.挂匾.掘井.开池.结网.栽种.纳畜.破土.修坟.立碑.安葬.入殓."},{"avoid":"开市.伐木.嫁娶.作梁.","date":"2020-1-19","suit":"入殓.除服.成服.移柩.启攒.安葬.修坟.立碑."},{"avoid":"开市.安床.","date":"2020-1-20","suit":"祭祀.作灶.入殓.除服.余事勿取."},{"avoid":"嫁娶.入殓.安葬.出行.","date":"2020-1-21","suit":"塑绘.开光.沐浴.冠笄.会亲友.作灶.放水.造畜椆栖."},{"avoid":"开仓.嫁娶.移徙.入宅.","date":"2020-1-22","suit":"祭祀.沐浴.祈福.斋醮.订盟.纳采.裁衣.拆卸.起基.竖柱.上梁.安床.入殓.除服.成服.移柩.启攒.挂匾.求嗣.出行.合帐.造畜椆栖."},{"avoid":"诸事不宜.","date":"2020-1-23","suit":"祭祀.解除.余事勿取."},{"avoid":"作灶.祭祀.上梁.出行.","date":"2020-1-24","suit":"沐浴.解除.订盟.纳采.裁衣.冠笄.拆卸.修造.动土.移徙.入宅.除服.成服.移柩.破土.启攒.安葬.扫舍.修坟.伐木.纳财.交易.立券."},{"avoid":"作灶.掘井.谢土.入宅.","date":"2020-1-25","suit":"出行.嫁娶.订盟.纳采.入殓.安床.启攒.安葬.祭祀.裁衣.会亲友.进人口."},{"avoid":"嫁娶.移徙.入宅.开光.","date":"2020-1-26","suit":"修饰垣墙.平治道涂.入殓.移柩.余事勿取."},{"avoid":"出行.治病.安葬.开市.","date":"2020-1-27","suit":"会亲友.纳采.进人口.修造.动土.竖柱.上梁.祭祀.开光.塑绘.祈福.斋醮.嫁娶.安床.移徙.入宅.安香.纳畜."},{"avoid":"造屋.开市.作灶.入宅.","date":"2020-1-28","suit":"祭祀.会亲友.出行.订盟.纳采.沐浴.修造.动土.祈福.斋醮.嫁娶.拆卸.安床.入殓.移柩.安葬.谢土.赴任.裁衣.竖柱.上梁.伐木.捕捉.栽种.破土.安门."},{"avoid":"诸事不宜.","date":"2020-1-29","suit":"解除.破屋.坏垣.余事勿取."},{"avoid":"入宅.安床.","date":"2020-1-30","suit":"塑绘.开光.出行.订盟.纳采.除服.成服.嫁娶.纳婿.入殓.移柩.启攒.安葬.立碑."},{"avoid":"破土.伐木.","date":"2020-1-31","suit":"入殓.除服.成服.移柩.启攒.安葬.立碑.余事勿取."}],"holiday":[{"desc":"1月1日放假一天","festival":"2020-1-1","list":[{"date":"2020-1-1","status":"1"}],"list#num#baidu":1,"name":"元旦","rest":"2019年12月30日和2019年12月31日请假两天,与周末连休可拼5天小长假。"},{"desc":"1月24日放假一天","festival":"2020-1-24","list":[{"date":"2020-1-24","status":"1"}],"list#num#baidu":1,"name":"除夕","rest":"农历腊月最后一天为除夕,即大年初一前夜,又称为年三十。"},{"desc":"1月24日(除夕)至1月30日放假7天,1月19日,2月1日上班","festival":"2020-1-25","list":[{"date":"2020-1-24","status":"1"},{"date":"2020-1-25","status":"1"},{"date":"2020-1-26","status":"1"},{"date":"2020-1-27","status":"1"},{"date":"2020-1-28","status":"1"},{"date":"2020-1-29","status":"1"},{"date":"2020-1-30","status":"1"},{"date":"2020-1-19","status":"2"},{"date":"2020-1-31","status":"1"},{"date":"2020-2-1","status":"1"},{"date":"2020-2-2","status":"1"}],"list#num#baidu":11,"name":"春节","rest":"2020年1月19日至2020年1月23日请假5天,与周末连休可拼13天长假。"},{"desc":"4月4日至4月6日放假3天","festival":"2020-4-4","list":[{"date":"2020-4-4","status":"1"},{"date":"2020-4-5","status":"1"},{"date":"2020-4-6","status":"1"}],"list#num#baidu":3,"name":"清明节","rest":"2020年4月7日至2020年4月10日请假4天,与周末连休可拼9天长假。"},{"desc":"5月1日至5月5日放假5天,4月26日,5月9日上班","festival":"2020-5-1","list":[{"date":"2020-5-1","status":"1"},{"date":"2020-5-2","status":"1"},{"date":"2020-5-3","status":"1"},{"date":"2020-5-4","status":"1"},{"date":"2020-5-5","status":"1"},{"date":"2020-4-26","status":"2"},{"date":"2020-5-9","status":"2"}],"list#num#baidu":7,"name":"劳动节","rest":"2020年4月26日至2020年4月30日请假5天,与周末连休可拼11天长假。"},{"desc":"6月25日至6月27日放假3天,6月28日上班","festival":"2020-6-25","list":[{"date":"2020-6-25","status":"1"},{"date":"2020-6-26","status":"1"},{"date":"2020-6-27","status":"1"},{"date":"2020-6-28","status":"2"}],"list#num#baidu":4,"name":"端午节","rest":"2020年6月22日至2020年6月24日请假3天,与周末连休可拼8天长假。"},{"desc":"10月1日至10月8日放假8天,9月27日,10月10日上班","festival":"2020-10-1","list":[{"date":"2020-10-1","status":"1"},{"date":"2020-10-2","status":"1"},{"date":"2020-10-3","status":"1"},{"date":"2020-10-4","status":"1"},{"date":"2020-10-5","status":"1"},{"date":"2020-10-6","status":"1"},{"date":"2020-10-7","status":"1"},{"date":"2020-10-8","status":"1"},{"date":"2020-9-27","status":"2"},{"date":"2020-10-10","status":"2"}],"list#num#baidu":10,"name":"中秋节","rest":"10月9日至10月10日请假2天,与周末连休可拼11天长假。"},{"desc":"10月1日至10月8日放假8天,9月27日,10月10日上班","festival":"2020-10-1","list":[{"date":"2020-10-1","status":"1"},{"date":"2020-10-2","status":"1"},{"date":"2020-10-3","status":"1"},{"date":"2020-10-4","status":"1"},{"date":"2020-10-5","status":"1"},{"date":"2020-10-6","status":"1"},{"date":"2020-10-7","status":"1"},{"date":"2020-10-8","status":"1"},{"date":"2020-9-27","status":"2"},{"date":"2020-10-10","status":"2"}],"list#num#baidu":10,"name":"国庆节","rest":"10月9日至10月10日请假2天,与周末连休可拼11天长假。"}],"holidaylist":[{"name":"元旦","startday":"2020-1-1"},{"name":"除夕","startday":"2020-1-24"},{"name":"春节","startday":"2020-1-25"},{"name":"清明节","startday":"2020-4-4"},{"name":"劳动节","startday":"2020-5-1"},{"name":"端午节","startday":"2020-6-25"},{"name":"中秋节","startday":"2020-10-1"},{"name":"国庆节","startday":"2020-10-1"}],"key":"2020年1月1日","selectday":"2020-1-1","url":"http:\/\/nourl.baidu.com\/6018","loc":"https:\/\/dss1.baidu.com\/8aQDcnSm2Q5IlBGlnYG\/q?r=2002753&k=2020%E5%B9%B41%E6%9C%881%E6%97%A5","SiteId":2002753,"_version":2767,"_select_time":1580102077,"clicklimit":"1-3","ExtendedLocation":"","OriginQuery":"2020","tplt":"calendar_new","resourceid":"6018","fetchkey":"6018_2020年1月1日","role_id":7,"disp_type":0,"appinfo":""}]}

//解析json中节假日。得到的内容中,status状态 1 为节假日 休息,2 为调休 上班
var holidays =[]  ; responseJson.data[0].holiday.forEach(e=>{e.list.forEach(x=>holidays.push(x))})
//数组转新的json,新json包含节假日和调休日
var newHolidayJson = JSON.stringify(holiday
//打印节假日
console.log(newHolidayJson)
[{"date":"2020-1-1","status":"1"},{"date":"2020-1-24","status":"1"},{"date":"2020-1-24","status":"1"},{"date":"2020-1-25","status":"1"},{"date":"2020-1-26","status":"1"},{"date":"2020-1-27","status":"1"},{"date":"2020-1-28","status":"1"},{"date":"2020-1-29","status":"1"},{"date":"2020-1-30","status":"1"},{"date":"2020-1-19","status":"2"},{"date":"2020-1-31","status":"1"},{"date":"2020-2-1","status":"1"},{"date":"2020-2-2","status":"1"},{"date":"2020-4-4","status":"1"},{"date":"2020-4-5","status":"1"},{"date":"2020-4-6","status":"1"},{"date":"2020-5-1","status":"1"},{"date":"2020-5-2","status":"1"},{"date":"2020-5-3","status":"1"},{"date":"2020-5-4","status":"1"},{"date":"2020-5-5","status":"1"},{"date":"2020-4-26","status":"2"},{"date":"2020-5-9","status":"2"},{"date":"2020-6-25","status":"1"},{"date":"2020-6-26","status":"1"},{"date":"2020-6-27","status":"1"},{"date":"2020-6-28","status":"2"},{"date":"2020-10-1","status":"1"},{"date":"2020-10-2","status":"1"},{"date":"2020-10-3","status":"1"},{"date":"2020-10-4","status":"1"},{"date":"2020-10-5","status":"1"},{"date":"2020-10-6","status":"1"},{"date":"2020-10-7","status":"1"},{"date":"2020-10-8","status":"1"},{"date":"2020-9-27","status":"2"},{"date":"2020-10-10","status":"2"},{"date":"2020-10-1","status":"1"},{"date":"2020-10-2","status":"1"},{"date":"2020-10-3","status":"1"},{"date":"2020-10-4","status":"1"},{"date":"2020-10-5","status":"1"},{"date":"2020-10-6","status":"1"},{"date":"2020-10-7","status":"1"},{"date":"2020-10-8","status":"1"},{"date":"2020-9-27","status":"2"},{"date":"2020-10-10","status":"2"}]


方式二:手动去维护部分数据

下载好github项目之后,进行如下操作
1.初始化数据库表sql

drop database if exists kaoqin;
create database kaoqin;

use kaoqin;
CREATE TABLE `no_work_day` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `day` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2.修改DBhelper数据库配置文件的连接地址和用户名密码
3.配置getHolidays方法中的法定节假日和调休日期

1、修改变量YEAR为对应年份.
2、如果年份对应的Date+YEAR不存在,则手动创建如Date2021.class,并维护法定节假日和调休日期) 
3、工厂类中添加 case 2021 的代码,返回 return new Date2021();

4.运行main方法 GetHolidaysApplication

执行完之后查看数据库插入的数据,控制台会提示成功插入的数量

5、查看生成的SQL

数据库插入的数据可以使用Navicate 
通过查询 select * from no_work_day where day like "%2019%"
得到结果集,结果集全选右键复制为insert语句则可以导出所有插入语句。

日期格式自定义,用20200101或2020-01-01


方式三:现成的sql数据

2021年非工作日
https://github.com/lufei222/san-holiday/blob/master/src/main/resources/2021.sql
2020年非工作日
https://github.com/lufei222/san-holiday/blob/master/src/main/resources/2020.sql

# 2020年不上班的日子 =[周末 + 节假日 -(被调成工作日的日期)]
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('1', '20200101');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('2', '20200104');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('3', '20200105');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('4', '20200111');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('5', '20200112');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('6', '20200118');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('7', '20200124');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('8', '20200125');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('9', '20200126');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('10', '20200127');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('11', '20200128');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('12', '20200129');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('13', '20200130');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('14', '20200202');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('15', '20200208');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('16', '20200209');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('17', '20200215');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('18', '20200216');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('19', '20200222');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('20', '20200223');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('21', '20200229');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('22', '20200301');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('23', '20200307');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('24', '20200308');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('25', '20200314');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('26', '20200315');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('27', '20200321');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('28', '20200322');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('29', '20200328');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('30', '20200329');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('31', '20200404');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('32', '20200405');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('33', '20200406');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('34', '20200411');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('35', '20200412');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('36', '20200418');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('37', '20200419');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('38', '20200425');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('39', '20200501');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('40', '20200502');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('41', '20200503');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('42', '20200504');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('43', '20200505');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('44', '20200510');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('45', '20200516');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('46', '20200517');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('47', '20200523');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('48', '20200524');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('49', '20200530');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('50', '20200531');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('51', '20200606');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('52', '20200607');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('53', '20200613');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('54', '20200614');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('55', '20200620');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('56', '20200621');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('57', '20200625');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('58', '20200626');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('59', '20200627');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('60', '20200704');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('61', '20200705');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('62', '20200711');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('63', '20200712');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('64', '20200718');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('65', '20200719');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('66', '20200725');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('67', '20200726');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('68', '20200801');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('69', '20200802');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('70', '20200808');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('71', '20200809');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('72', '20200815');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('73', '20200816');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('74', '20200822');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('75', '20200823');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('76', '20200829');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('77', '20200830');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('78', '20200905');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('79', '20200906');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('80', '20200912');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('81', '20200913');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('82', '20200919');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('83', '20200920');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('84', '20200926');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('85', '20201001');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('86', '20201002');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('87', '20201003');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('88', '20201004');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('89', '20201005');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('90', '20201006');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('91', '20201007');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('92', '20201008');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('93', '20201011');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('94', '20201017');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('95', '20201018');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('96', '20201024');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('97', '20201025');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('98', '20201031');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('99', '20201101');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('100', '20201107');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('101', '20201108');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('102', '20201114');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('103', '20201115');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('104', '20201121');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('105', '20201122');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('106', '20201128');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('107', '20201129');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('108', '20201205');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('109', '20201206');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('110', '20201212');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('111', '20201213');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('112', '20201219');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('113', '20201220');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('114', '20201226');
INSERT INTO `no_work_day` (`id`, `day`) VALUES ('115', '20201227');



相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页