C# 获取全年的节假日(全文特指非工作日),周末 + 节假日 -(被调成工作日的日期)= 节假日
方法一 : 調(diào)用第三方接口獲得節(jié)假日
周末 + 節(jié)假日 -(被調(diào)成工作日的日期)= 節(jié)假日 這種方式獲得節(jié)假日往往需要進(jìn)行調(diào)整,因?yàn)槊總€(gè)公司放假時(shí)間不一樣,所以還是建議結(jié)合第一種方式使用
調(diào)用api查詢
方式一:調(diào)用api查詢
首先查詢百度萬年歷節(jié)接口(其中包含全年節(jié)假日數(shù)據(jù)),得到j(luò)son數(shù)據(jù) (全年節(jié)假日信息在json的holiday中,query=2020,其實(shí)默認(rèn)就是202001,其他月份的萬年歷請(qǐng)求如query=202004)
請(qǐng)求的api:
https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=2020&resource_id=6018返回的json內(nèi)容如下,
{"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":"求嗣.齋醮.塑繪.訂盟.納采.出火.拆卸.修造.動(dòng)土.造橋.安機(jī)械.栽種.納畜.牧養(yǎng).入殮.除服.成服.移柩.破土.安葬."},{"avoid":"開市.安葬.","date":"2020-1-3","suit":"嫁娶.訂盟.納采.祭祀.祈福.修造.動(dòng)土.移徙.入宅."},{"avoid":"諸事不宜.","date":"2020-1-4","suit":"治病.破屋.壞垣.余事勿取."},{"avoid":"造橋.安門.理發(fā).造廟.栽種.作灶.","date":"2020-1-5","suit":"祭祀.祈福.求嗣.齋醮.開光.入學(xué).訂盟.冠笄.伐木.修造.動(dòng)土.起基.放水.交易.開池."},{"avoid":"祈福.嫁娶.安床.入宅.造船.","date":"2020-1-6","suit":"沐浴.開倉.出貨財(cái).開市.交易.立券.納財(cái).栽種.納畜.牧養(yǎng).畋獵.入殮.破土.安葬."},{"avoid":"造廟.入宅.修造.安葬.行喪.嫁娶.","date":"2020-1-7","suit":"祭祀.沐浴.補(bǔ)垣.塞穴.斷蟻.解除.余事勿取."},{"avoid":"開市.安床.安葬.修墳.","date":"2020-1-8","suit":"嫁娶.納采.訂盟.問名.祭祀.冠笄.裁衣.會(huì)親友.進(jìn)人口.納財(cái).捕捉.作灶."},{"avoid":"造廟.嫁娶.出行.動(dòng)土.安葬.行喪.","date":"2020-1-9","suit":"訂盟.納采.會(huì)親友.祭祀.齋醮.沐浴.塑繪.出火.開光.豎柱.上梁.開市.交易.立券.作梁.開柱眼.伐木.架馬.安門.安床.拆卸.牧養(yǎng).造畜椆棲.掘井."},{"avoid":"開光.嫁娶.開市.動(dòng)土.破土.","date":"2020-1-10","suit":"交易.立券.納財(cái).安床.裁衣.造畜椆棲.安葬.謝土.啟攢.除服.成服.修墳.立碑.移柩.入殮."},{"avoid":"破土.動(dòng)土.安葬.","date":"2020-1-11","suit":"祭祀.解除.教牛馬.會(huì)親友.余事勿取."},{"avoid":"探病.祭祀.出行.上梁.造屋.謝土.安葬.","date":"2020-1-12","suit":"納采.訂盟.移徙.納財(cái).開市.交易.立券.入宅.會(huì)親友.解除.求醫(yī).治病.入學(xué).安床.安門.安香.出火.拆卸.掃舍.入宅.掛匾.開生墳.合壽木.破土.修墳.啟攢.入殮."},{"avoid":"入宅.開光.開市.動(dòng)土.","date":"2020-1-13","suit":"嫁娶.訂盟.納采.祭祀.祈福.求嗣.會(huì)親友.解除.出行.入學(xué).納財(cái).開市.交易.立券.習(xí)藝.經(jīng)絡(luò).安床.開倉.出貨財(cái).納畜.安葬.啟攢.修墳.入殮."},{"avoid":"移徙.入宅.造廟.作灶.治病.安葬.","date":"2020-1-14","suit":"祭祀.冠笄.嫁娶.會(huì)親友.進(jìn)人口.裁衣.結(jié)網(wǎng).平治道涂."},{"avoid":"嫁娶.安葬.","date":"2020-1-15","suit":"祭祀.安碓硙.結(jié)網(wǎng).余事勿取."},{"avoid":"造屋.開市.動(dòng)土.破土.","date":"2020-1-16","suit":"嫁娶.祭祀.沐浴.裁衣.出行.理發(fā).移徙.捕捉.畋獵.放水.入宅.除服.成服.啟攢.安葬.移柩.入殮."},{"avoid":"嫁娶.開市.安葬.","date":"2020-1-17","suit":"破屋.壞垣.余事勿取."},{"avoid":"祈福.嫁娶.造廟.安床.謝土.","date":"2020-1-18","suit":"納采.訂盟.祭祀.求嗣.出火.塑繪.裁衣.會(huì)親友.入學(xué).拆卸.掃舍.造倉.掛匾.掘井.開池.結(jié)網(wǎng).栽種.納畜.破土.修墳.立碑.安葬.入殮."},{"avoid":"開市.伐木.嫁娶.作梁.","date":"2020-1-19","suit":"入殮.除服.成服.移柩.啟攢.安葬.修墳.立碑."},{"avoid":"開市.安床.","date":"2020-1-20","suit":"祭祀.作灶.入殮.除服.余事勿取."},{"avoid":"嫁娶.入殮.安葬.出行.","date":"2020-1-21","suit":"塑繪.開光.沐浴.冠笄.會(huì)親友.作灶.放水.造畜椆棲."},{"avoid":"開倉.嫁娶.移徙.入宅.","date":"2020-1-22","suit":"祭祀.沐浴.祈福.齋醮.訂盟.納采.裁衣.拆卸.起基.豎柱.上梁.安床.入殮.除服.成服.移柩.啟攢.掛匾.求嗣.出行.合帳.造畜椆棲."},{"avoid":"諸事不宜.","date":"2020-1-23","suit":"祭祀.解除.余事勿取."},{"avoid":"作灶.祭祀.上梁.出行.","date":"2020-1-24","suit":"沐浴.解除.訂盟.納采.裁衣.冠笄.拆卸.修造.動(dòng)土.移徙.入宅.除服.成服.移柩.破土.啟攢.安葬.掃舍.修墳.伐木.納財(cái).交易.立券."},{"avoid":"作灶.掘井.謝土.入宅.","date":"2020-1-25","suit":"出行.嫁娶.訂盟.納采.入殮.安床.啟攢.安葬.祭祀.裁衣.會(huì)親友.進(jìn)人口."},{"avoid":"嫁娶.移徙.入宅.開光.","date":"2020-1-26","suit":"修飾垣墻.平治道涂.入殮.移柩.余事勿取."},{"avoid":"出行.治病.安葬.開市.","date":"2020-1-27","suit":"會(huì)親友.納采.進(jìn)人口.修造.動(dòng)土.豎柱.上梁.祭祀.開光.塑繪.祈福.齋醮.嫁娶.安床.移徙.入宅.安香.納畜."},{"avoid":"造屋.開市.作灶.入宅.","date":"2020-1-28","suit":"祭祀.會(huì)親友.出行.訂盟.納采.沐浴.修造.動(dòng)土.祈福.齋醮.嫁娶.拆卸.安床.入殮.移柩.安葬.謝土.赴任.裁衣.豎柱.上梁.伐木.捕捉.栽種.破土.安門."},{"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日請(qǐng)假兩天,與周末連休可拼5天小長假。"},{"desc":"1月24日放假一天","festival":"2020-1-24","list":[{"date":"2020-1-24","status":"1"}],"list#num#baidu":1,"name":"除夕","rest":"農(nóng)歷臘月最后一天為除夕,即大年初一前夜,又稱為年三十。"},{"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":"春節(jié)","rest":"2020年1月19日至2020年1月23日請(qǐng)假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":"清明節(jié)","rest":"2020年4月7日至2020年4月10日請(qǐng)假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":"勞動(dòng)節(jié)","rest":"2020年4月26日至2020年4月30日請(qǐng)假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":"端午節(jié)","rest":"2020年6月22日至2020年6月24日請(qǐng)假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":"中秋節(jié)","rest":"10月9日至10月10日請(qǐng)假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":"國慶節(jié)","rest":"10月9日至10月10日請(qǐng)假2天,與周末連休可拼11天長假。"}],"holidaylist":[{"name":"元旦","startday":"2020-1-1"},{"name":"除夕","startday":"2020-1-24"},{"name":"春節(jié)","startday":"2020-1-25"},{"name":"清明節(jié)","startday":"2020-4-4"},{"name":"勞動(dòng)節(jié)","startday":"2020-5-1"},{"name":"端午節(jié)","startday":"2020-6-25"},{"name":"中秋節(jié)","startday":"2020-10-1"},{"name":"國慶節(jié)","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復(fù)制到谷歌控制臺(tái)執(zhí)行js解析得到節(jié)假日
接著再瀏覽器控制臺(tái)或者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":"求嗣.齋醮.塑繪.訂盟.納采.出火.拆卸.修造.動(dòng)土.造橋.安機(jī)械.栽種.納畜.牧養(yǎng).入殮.除服.成服.移柩.破土.安葬."},{"avoid":"開市.安葬.","date":"2020-1-3","suit":"嫁娶.訂盟.納采.祭祀.祈福.修造.動(dòng)土.移徙.入宅."},{"avoid":"諸事不宜.","date":"2020-1-4","suit":"治病.破屋.壞垣.余事勿取."},{"avoid":"造橋.安門.理發(fā).造廟.栽種.作灶.","date":"2020-1-5","suit":"祭祀.祈福.求嗣.齋醮.開光.入學(xué).訂盟.冠笄.伐木.修造.動(dòng)土.起基.放水.交易.開池."},{"avoid":"祈福.嫁娶.安床.入宅.造船.","date":"2020-1-6","suit":"沐浴.開倉.出貨財(cái).開市.交易.立券.納財(cái).栽種.納畜.牧養(yǎng).畋獵.入殮.破土.安葬."},{"avoid":"造廟.入宅.修造.安葬.行喪.嫁娶.","date":"2020-1-7","suit":"祭祀.沐浴.補(bǔ)垣.塞穴.斷蟻.解除.余事勿取."},{"avoid":"開市.安床.安葬.修墳.","date":"2020-1-8","suit":"嫁娶.納采.訂盟.問名.祭祀.冠笄.裁衣.會(huì)親友.進(jìn)人口.納財(cái).捕捉.作灶."},{"avoid":"造廟.嫁娶.出行.動(dòng)土.安葬.行喪.","date":"2020-1-9","suit":"訂盟.納采.會(huì)親友.祭祀.齋醮.沐浴.塑繪.出火.開光.豎柱.上梁.開市.交易.立券.作梁.開柱眼.伐木.架馬.安門.安床.拆卸.牧養(yǎng).造畜椆棲.掘井."},{"avoid":"開光.嫁娶.開市.動(dòng)土.破土.","date":"2020-1-10","suit":"交易.立券.納財(cái).安床.裁衣.造畜椆棲.安葬.謝土.啟攢.除服.成服.修墳.立碑.移柩.入殮."},{"avoid":"破土.動(dòng)土.安葬.","date":"2020-1-11","suit":"祭祀.解除.教牛馬.會(huì)親友.余事勿取."},{"avoid":"探病.祭祀.出行.上梁.造屋.謝土.安葬.","date":"2020-1-12","suit":"納采.訂盟.移徙.納財(cái).開市.交易.立券.入宅.會(huì)親友.解除.求醫(yī).治病.入學(xué).安床.安門.安香.出火.拆卸.掃舍.入宅.掛匾.開生墳.合壽木.破土.修墳.啟攢.入殮."},{"avoid":"入宅.開光.開市.動(dòng)土.","date":"2020-1-13","suit":"嫁娶.訂盟.納采.祭祀.祈福.求嗣.會(huì)親友.解除.出行.入學(xué).納財(cái).開市.交易.立券.習(xí)藝.經(jīng)絡(luò).安床.開倉.出貨財(cái).納畜.安葬.啟攢.修墳.入殮."},{"avoid":"移徙.入宅.造廟.作灶.治病.安葬.","date":"2020-1-14","suit":"祭祀.冠笄.嫁娶.會(huì)親友.進(jìn)人口.裁衣.結(jié)網(wǎng).平治道涂."},{"avoid":"嫁娶.安葬.","date":"2020-1-15","suit":"祭祀.安碓硙.結(jié)網(wǎng).余事勿取."},{"avoid":"造屋.開市.動(dòng)土.破土.","date":"2020-1-16","suit":"嫁娶.祭祀.沐浴.裁衣.出行.理發(fā).移徙.捕捉.畋獵.放水.入宅.除服.成服.啟攢.安葬.移柩.入殮."},{"avoid":"嫁娶.開市.安葬.","date":"2020-1-17","suit":"破屋.壞垣.余事勿取."},{"avoid":"祈福.嫁娶.造廟.安床.謝土.","date":"2020-1-18","suit":"納采.訂盟.祭祀.求嗣.出火.塑繪.裁衣.會(huì)親友.入學(xué).拆卸.掃舍.造倉.掛匾.掘井.開池.結(jié)網(wǎng).栽種.納畜.破土.修墳.立碑.安葬.入殮."},{"avoid":"開市.伐木.嫁娶.作梁.","date":"2020-1-19","suit":"入殮.除服.成服.移柩.啟攢.安葬.修墳.立碑."},{"avoid":"開市.安床.","date":"2020-1-20","suit":"祭祀.作灶.入殮.除服.余事勿取."},{"avoid":"嫁娶.入殮.安葬.出行.","date":"2020-1-21","suit":"塑繪.開光.沐浴.冠笄.會(huì)親友.作灶.放水.造畜椆棲."},{"avoid":"開倉.嫁娶.移徙.入宅.","date":"2020-1-22","suit":"祭祀.沐浴.祈福.齋醮.訂盟.納采.裁衣.拆卸.起基.豎柱.上梁.安床.入殮.除服.成服.移柩.啟攢.掛匾.求嗣.出行.合帳.造畜椆棲."},{"avoid":"諸事不宜.","date":"2020-1-23","suit":"祭祀.解除.余事勿取."},{"avoid":"作灶.祭祀.上梁.出行.","date":"2020-1-24","suit":"沐浴.解除.訂盟.納采.裁衣.冠笄.拆卸.修造.動(dòng)土.移徙.入宅.除服.成服.移柩.破土.啟攢.安葬.掃舍.修墳.伐木.納財(cái).交易.立券."},{"avoid":"作灶.掘井.謝土.入宅.","date":"2020-1-25","suit":"出行.嫁娶.訂盟.納采.入殮.安床.啟攢.安葬.祭祀.裁衣.會(huì)親友.進(jìn)人口."},{"avoid":"嫁娶.移徙.入宅.開光.","date":"2020-1-26","suit":"修飾垣墻.平治道涂.入殮.移柩.余事勿取."},{"avoid":"出行.治病.安葬.開市.","date":"2020-1-27","suit":"會(huì)親友.納采.進(jìn)人口.修造.動(dòng)土.豎柱.上梁.祭祀.開光.塑繪.祈福.齋醮.嫁娶.安床.移徙.入宅.安香.納畜."},{"avoid":"造屋.開市.作灶.入宅.","date":"2020-1-28","suit":"祭祀.會(huì)親友.出行.訂盟.納采.沐浴.修造.動(dòng)土.祈福.齋醮.嫁娶.拆卸.安床.入殮.移柩.安葬.謝土.赴任.裁衣.豎柱.上梁.伐木.捕捉.栽種.破土.安門."},{"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日請(qǐng)假兩天,與周末連休可拼5天小長假。"},{"desc":"1月24日放假一天","festival":"2020-1-24","list":[{"date":"2020-1-24","status":"1"}],"list#num#baidu":1,"name":"除夕","rest":"農(nóng)歷臘月最后一天為除夕,即大年初一前夜,又稱為年三十。"},{"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":"春節(jié)","rest":"2020年1月19日至2020年1月23日請(qǐng)假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":"清明節(jié)","rest":"2020年4月7日至2020年4月10日請(qǐng)假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":"勞動(dòng)節(jié)","rest":"2020年4月26日至2020年4月30日請(qǐng)假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":"端午節(jié)","rest":"2020年6月22日至2020年6月24日請(qǐng)假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":"中秋節(jié)","rest":"10月9日至10月10日請(qǐng)假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":"國慶節(jié)","rest":"10月9日至10月10日請(qǐng)假2天,與周末連休可拼11天長假。"}],"holidaylist":[{"name":"元旦","startday":"2020-1-1"},{"name":"除夕","startday":"2020-1-24"},{"name":"春節(jié)","startday":"2020-1-25"},{"name":"清明節(jié)","startday":"2020-4-4"},{"name":"勞動(dòng)節(jié)","startday":"2020-5-1"},{"name":"端午節(jié)","startday":"2020-6-25"},{"name":"中秋節(jié)","startday":"2020-10-1"},{"name":"國慶節(jié)","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中節(jié)假日。得到的內(nèi)容中,status狀態(tài) 1 為節(jié)假日 休息,2 為調(diào)休 上班
var holidays =[] ; responseJson.data[0].holiday.forEach(e=>{e.list.forEach(x=>holidays.push(x))})
//數(shù)組轉(zhuǎn)新的json,新json包含節(jié)假日和調(diào)休日
var newHolidayJson = JSON.stringify(holiday
//打印節(jié)假日
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
方法二 : 代碼運(yùn)行獲得節(jié)假日
周末 + 節(jié)假日 -(被調(diào)成工作日的日期)= 節(jié)假日
1.修改DBhelper數(shù)據(jù)庫配置文件
2.執(zhí)行db.sql文件
3.配置getHolidays方法中的法定節(jié)假日和調(diào)休日期
4.運(yùn)行com.holiday.GetHolidays 的 main方法
日期格式自定義getHolidays的SEPARATOR參數(shù)內(nèi)容,用20200101或2020-01-01
方法三:直接執(zhí)行拿2020.sql 日期數(shù)據(jù) 到自己的數(shù)據(jù)庫
createDB.sql
2020.sql
github地址:https://github.com/lufei222/san-holiday
總結(jié)
以上是生活随笔為你收集整理的C# 获取全年的节假日(全文特指非工作日),周末 + 节假日 -(被调成工作日的日期)= 节假日的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 王者荣耀信用卡怎么绑定游戏
- 下一篇: 使用 zssh 进行 Zmodem 文件