C#/.Net判断是否为周末/节假日
程序员文章站
2022-06-30 22:55:22
判断节假日请求的Api:http://tool.bitefu.net/jiari/ /// /// 判断是不是周末/节假日 /// /// 日期 /// 周末和节假日返回true,工作日 ......
判断节假日请求的api:http://tool.bitefu.net/jiari/
/// <summary> /// 判断是不是周末/节假日 /// </summary> /// <param name="date">日期</param> /// <returns>周末和节假日返回true,工作日返回false</returns> public static async task<bool> isholidaybydate(datetime date) { var isholiday = false; var webclient = new system.net.webclient(); var postvars = new system.collections.specialized.namevaluecollection { { "d", date.tostring("yyyymmdd") }//参数 }; try { var day = date.dayofweek; //判断是否为周末 if (day == dayofweek.sunday || day == dayofweek.saturday) return true; //0为工作日,1为周末,2为法定节假日 var byteresult = await webclient.uploadvaluestaskasync("http://tool.bitefu.net/jiari/", "post", postvars);//请求地址,传参方式,参数集合 var result = encoding.utf8.getstring(byteresult);//获取返回值 if (result == "1" || result == "2") isholiday = true; } catch { isholiday = false; } return isholiday; }