C#判断是否是节假日

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace holiday
{
    class Program
    {
        static void Main(string[] args)
        {
            //引用Newtonsoft.Json.dll
            //
            //http://www.downza.cn/soft/212414.html 下载地址
 
            bool isHoliday = IsHolidayByDate("20180101");
 
        }
 
        /// <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
            {
 
                 //  用法举例<br>                 //  检查具体日期是否为节假日,工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2;
                //   检查一个日期是否为节假日 http://www.easybots.cn/api/holiday.php?d=20130101
               //  检查多个日期是否为节假日 http://www.easybots.cn/api/holiday.php?d=20130101,20130103,20130105,20130201
              //获取2012年1月份节假日 http://www.easybots.cn/api/holiday.php?m=201201
             //获取2013年1 / 2月份节假日 http://www.easybots.cn/api/holiday.php?m=201301,201302
 
                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;
        }
    }
}

  

posted @   想念熊小米  阅读(7340)  评论(2编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示