int months = applicationLookBack.LookBackPeriod; //In Months
public class DateRange
{
public virtual DateTime? Startdate { get; set; }
public virtual DateTime? Enddate { get; set; }
}
计算和填充此DateRange的最佳方法是什么 月数?
答案 0 :(得分:1)
int months = 14;
int currentYear = DateTime.Now.Year;
DateTime firstDate = new DateTime(currentYear, 1, 1);
DateTime lastDate = firstDate.AddMonths(months - 1);
var lastMonthDays = DateTime.DaysInMonth(lastDate.Year, lastDate.Month);
lastDate = lastDate.AddDays(lastMonthDays - 1);