码迷,mamicode.com
首页 > Web开发 > 详细

.net 获取当前周及根据年和周获取起始结束时间

时间:2015-03-11 12:51:33      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

获取当前日期周数
int str = new System.Globalization.GregorianCalendar().GetWeekOfYear(System.DateTime.Now, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday);

根据周得到启示日期和截止日期
private static void GetWeekSpan(out DateTime dtBeginDate, out DateTime dtEndDate, int iWeeks)
{
int iCurrentYear = DateTime.Now.Year;
DateTime dtFirstDate = new DateTime(iCurrentYear, 1, 1);
int iDays = (iWeeks - 1) * 7;
dtFirstDate = dtFirstDate.AddDays(iDays);
int iDaysOfWeek = (int)dtFirstDate.DayOfWeek;
dtBeginDate = dtFirstDate.AddDays(-(iDaysOfWeek - 1)-1);
dtEndDate = dtFirstDate.AddDays(7 - iDaysOfWeek-1);
}

.net 获取当前周及根据年和周获取起始结束时间

标签:

原文地址:http://www.cnblogs.com/lc-chenlong/p/4329504.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!