根据时间段查询出范围内所有日期
作者:互联网
/// <summary>
/// 根据时间段查询范围内所有日期
/// </summary>
/// <param name="startDateTime">开始时间</param>
/// <param name="EndDateTime">结束时间</param>
/// <returns></returns>
[HttpGet]
[Authorize]
public async Task<MessageModel<List<DateTime>>> GetAllDate(DateTime? startDateTime = null , DateTime? EndDateTime = null)
{
MessageModel<List<DateTime>> result = new MessageModel<List<DateTime>>()
{
success = false
};
try
{
List<DateTime> dateTimeList = new List<DateTime>();
DateTime dateTime = new DateTime();
//循环比较,取出日期;
for (dateTime = Convert.ToDateTime(startDateTime); dateTime.CompareTo(EndDateTime) <= 0; dateTime = dateTime.AddDays(1))
{
dateTimeList.Add(dateTime);
}
result.response = dateTimeList;
result.success = true;
result.msg = "查询成功";
}
catch (Exception ex)
{
result.msg = "获取数据异常" + ex.Message;
}
return result;
}
原文:https://www.cnblogs.com/hugeboke/p/15745079.html
标签:null,查询,EndDateTime,DateTime,MessageModel,日期,时间段,new,dateTime 来源: https://www.cnblogs.com/Stars0121/p/16520133.html