/// <summary>
/// 获取指定日期,在为一年中为第几周
/// </summary>
/// <param name="dt">指定时间</param>
/// <reutrn>返回第几周</reutrn>
public static int GetWeekOfYear(DateTime dt)
{
System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar();
int weekOfYear = gc.GetWeekOfYear(dt, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);
return weekOfYear;
}
public static int WeekOfMonth(DateTime day, int WeekStart)
{
//WeekStart
//1表示 周一至周日 为一周
//2表示 周日至周六 为一周
DateTime FirstofMonth;
FirstofMonth = Convert.ToDateTime(day.Date.Year + "-" + day.Date.Month + "-" + 1);
int i = (int)FirstofMonth.Date.DayOfWeek;
if (i == 0)
{
i = 7;
}
if (WeekStart == 1)
{
return (day.Date.Day + i - 2) / 7 + 1;
}
if (WeekStart == 2)
{
return (day.Date.Day + i - 1) / 7;
}
return 0;
//错误返回值0
}
获取此实例所表示的日期为该月中的第几天
DateTime.Today.Day