c#日期相关代码

//当年开始日期、结束日期
DateTime currentDate = DateTime.Now.Date;
DateTime yearStart = DateTime.Parse($"{currentDate.Year}-1-1");//开始日期

DateTime yearEnd = yearStart.AddYears(1).AddDays(-1).AddSeconds(-1);

int monthdays = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(currentDate.Year, 12);//月天数


//当月开始日期、结束日期
DateTime monthStart = currentDate.AddDays(1 - currentDate.Day).Date;
DateTime monthEnd = currentDate.AddDays(1 - currentDate.Day).Date.AddMonths(1).AddSeconds(-1);
//上个月开始日期、结束日期

DateTime lastMonthStart = currentDate.AddMonths(-1).Date.AddDays(1 - currentDate.Day);
DateTime lastMonthEnd = DateTime.Parse(currentDate.AddDays(1 - currentDate.Day).ToShortDateString()).AddSeconds(-1);

c#日期相关代码

上一篇:【UE4】Windows 的几种打包方式


下一篇:WPF之UI布局