在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
原文地址:https://www.xin3721.com/ArticlecSharp/c14100.html 判断节假日请求的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; }
|
请发表评论