使用GregorianCalendar 获得日期是年中第几周第几天
public class Common
{
/// <summary>
/// 获取日期是年中的第几周
/// </summary>
/// <param name="dtime"></param>
/// <returns></returns>
public static int GetWeekIndexOfYear(DateTime dtime)
{
GregorianCalendar gc = new GregorianCalendar();
int weekOfYear = gc.GetWeekOfYear(dtime, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
return weekOfYear;
} /// <summary>
/// 获取日期是本周的第几天
/// </summary>
/// <param name="dtime"></param>
/// <returns></returns>
public static DayOfWeek GetDateIndexOfWeekAndMonth(DateTime dtime, out int indexOfMonth)
{
GregorianCalendar gc = new GregorianCalendar();
indexOfMonth = gc.GetDayOfMonth(dtime);
DayOfWeek dayOfWeek = gc.GetDayOfWeek(dtime);
return dayOfWeek;
}
}