CFXIXI工作室首页
CF西西的博客 | All posts tagged 'C-周开始时间-周结束时间'

C#根据日期获得这周开始时间、结束时间的方法

8. 三月 2012
周开始时间   /// <summary> /// Get the first date of the week for a certain date, provided /// that the first day of the week is Monday, the first week of /// a year is the one that includes the first Thursday of that /// year and the last week of a year is the one that immediately /// precedes the first calendar week of the next year. /// </summary> /// <param name="date">ISO 8601 date of interest.</param> /// <returns>The first week date.</returns> public static DateTime GetFirstDateOfWeek(DateTime date) { if (date == DateTime.MinValue) return date; int week = GetWeekNumber(date); while (week == GetWeekNumber(date)) date = date.AddDays(-1); return date.AddDays(1); }     周结束时间   /// <summary> /// Get the last date of the week for a certain date, provided /// that the first day of the week is Monday, the first week of /// a year is the one that includes the first Thursday of that /// year and the last week of a year is the one that immediately /// precedes the first calendar week of the next year. /// </summary> /// <param name="date">ISO 8601 date of interest.</param> /// <returns>The first week date.</returns> public static DateTime GetLastDateOfWeek(DateTime date) { if (date == DateTime.MaxValue) return date; int week = GetWeekNumber(date); while (week == GetWeekNumber(date)) date = date.AddDays(1); return date.AddDays(-1); }

C#