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;
}
C# 判斷是否是節假日