C#.NET获取每年国家法定节假日清单
目录
测试
C# 全选
var list= HolidayHelper.GetHoliday(2024);
返回结果
C# 全选
/// <summary>
/// 法定节假日api
/// </summary>
public class HolidayHelper
{
public static List<HolidayItem> GetHoliday(int year)
{
var listResult = new List<HolidayItem>();
var url = "https://timor.tech/api/holiday/year/" + year;
var json = HttpTools.Get(url, "");
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<HolidayApiResult>(json);
var t = data.holiday as Newtonsoft.Json.Linq.JObject;
foreach (var item in t)
{
var obj = item.Value.ToObject<HolidayItem>();
if (obj != null) listResult.Add(obj);
}
return listResult;
}
}
C# 全选
public class HolidayItem
{
/// <summary>
/// 是否节假日
/// </summary>
public bool holiday { get; set; }
/// <summary>
/// 节假日名称,如:元旦
/// </summary>
public string name { get; set; }
/// <summary>
/// 工资倍数
/// </summary>
public int wage { get; set; }
/// <summary>
/// 节假日日期
/// </summary>
public DateTime date { get; set; }
public int rest { get; set; }
}
C# 全选
/// <summary>
/// api接口返回的对象模型
/// </summary>
public class HolidayApiResult
{
public int code { get; set; }
public object holiday { get; set; }
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网