C#/.Net判断是否为周末/节假日

判断节假日请求的Api:http://tool.bitefu.net/jiari/

 

        /// 
        /// 判断是不是周末/节假日
        /// 
        /// 日期
        /// 周末和节假日返回true,工作日返回false
        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

 

转载于:https://www.cnblogs.com/heheblog/p/net_study_20190115.html

你可能感兴趣的:(C#/.Net判断是否为周末/节假日)