码迷,mamicode.com
首页 > Windows程序 > 详细

C# 判断是否是节假日

时间:2015-04-03 09:05:21      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

1.引用Newtonsoft.Json.dll

2.

   /// <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;
        }

C# 判断是否是节假日

标签:

原文地址:http://www.cnblogs.com/MyBeN/p/4389075.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!