C# 获取全年的节假日(全文特指非工作日),周末 + 节假日 -(被调成工作日的日期)= 节假日
方法一 : 调用第三方接口获得节假日
周末 + 节假日 -(被调成工作日的日期)= 节假日 这种方式获得节假日往往需要进行调整,因为每个公司放假时间不一样,所以还是建议结合第一种方式使用
调用api查询
方式一:调用api查询
首先查询百度万年历节接口(其中包含全年节假日数据),得到json数据 (全年节假日信息在json的holiday中,query=2020,其实默认就是202001,其他月份的万年历请求如query=202004)
请求的api:
https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=2020&resource_id=6018 返回的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"}]
api来源: http://timor.tech/api/holiday
方法二 : 代码运行获得节假日
周末 + 节假日 -(被调成工作日的日期)= 节假日
1.修改DBhelper数据库配置文件
2.执行db.sql文件
3.配置getHolidays方法中的法定节假日和调休日期
4.运行com.holiday.GetHolidays 的 main方法
日期格式自定义getHolidays的SEPARATOR参数内容,用20200101或2020-01-01
方法三:直接执行拿2020.sql 日期数据 到自己的数据库
-
createDB.sql
-
2020.sql
github地址:https://github.com/lufei222/san-holiday