您的位置:首页 > 其它

.net中获取周一、月初、月末、年初、年末

2013-05-28 07:13 288 查看
DateTime startWeek = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d"))); //本周周一

DateTime endWeek = startWeek.AddDays(6); //本周周日

DateTime startMonth = dt.AddDays(1 - dt.Day); //本月月初

DateTime endMonth = startMonth.AddMonths(1).AddDays(-1); //本月月末

//DateTime endMonth = startMonth.AddDays((dt.AddMonths(1) - dt).Days - 1); //本月月末

DateTime startQuarter = dt.AddMonths(0 - (dt.Month - 1) % 3).AddDays(1 - dt.Day); //本季度初

DateTime endQuarter = startQuarter.AddMonths(3).AddDays(-1); //本季度末

DateTime startYear = new DateTime(dt.Year, 1, 1); //本年年初

DateTime endYear = new DateTime(dt.Year, 12, 31); //本年年末
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐