zoukankan      html  css  js  c++  java
  • C# 判断是否是节假日

    1.引用Newtonsoft.Json.dll

    2.用API

       /// <summary>
            /// 判断是不是节假日,节假日返回true 
            /// </summary>
            /// <param name="date">日期格式:yyyyMMdd</param>
            /// <returns></returns>
            public static bool IsHolidayByDate(string date)
            {
                bool isHoliday = false;
                System.Net.WebClient WebClientObj = new System.Net.WebClient();
                System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection();
                PostVars.Add("d", date);//参数
                try
                {
                    byte[] byRemoteInfo = WebClientObj.UploadValues(@"http://www.easybots.cn/api/holiday.php", "POST", PostVars);//请求地址,传参方式,参数集合
                    string sRemoteInfo = System.Text.Encoding.UTF8.GetString(byRemoteInfo);//获取返回值

                    string result = JObject.Parse(sRemoteInfo)[date].ToString();
                    if (result == "0")
                    {
                        isHoliday = false;
                    }
                    else if (result == "1" || result == "2")
                    {
                        isHoliday = true;
                    }
                }
                catch
                {
                    isHoliday = false;
                }
                return isHoliday;
            }

  • 相关阅读:
    Javascript高级篇-Function对象
    Object类、instanceof
    [一]Head First设计模式之【策略模式】(鸭子设计的优化历程)
    匿名内部类
    设计模式之单例模式
    长江商业评论读书笔记
    [转]Freemarker数据类型转换
    面向对象编程——概论(一)
    IP地址处理模块IPy
    系统性能模块psutil
  • 原文地址:https://www.cnblogs.com/AlexLeeLi/p/6835176.html
Copyright © 2011-2022 走看看