zoukankan      html  css  js  c++  java
  • C#/.Net判断是否为周末/节假日

    判断节假日请求的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
  • 相关阅读:
    HTTP 缓存图解
    http协议构成整理
    HTTP2.0
    Event Loop
    斐波那契数列
    归并排序
    快速排序
    史上最全前端资源
    Js 将 Date 转化为指定格式的String
    vue-cli webpack全局引入jquery
  • 原文地址:https://www.cnblogs.com/heheblog/p/net_study_20190115.html
Copyright © 2011-2022 走看看