判斷節假日請求的Api:http://tool.bitefu.net/jiari/ /// <summary> /// 判斷是不是周末/節假日 /// </summary> /// <param name="date">日期</param> /// <returns>周末和節假日返回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; }View Code