日期
怎么求一年的第几周的 起始 时间 ,列入2012的 第13周的起始时间
急!很急
--------------------编程问答--------------------
拿去用
/// <summary>
/// 返回日期在年份中的第几周
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public int GetWeekNumOfYear(DateTime dt)
{
int days = dt.DayOfYear + (7 - ((int)dt.DayOfWeek + 1));
return days / 7 + (days % 7 == 0 ? 0 : 1);
}
public DateTime GetDateTimeForWeekFirstDay(int Year, int num)
{
DateTime day = new DateTime(Year, 1, 1);
return day.AddDays(7 * (num - 1) - ((int)day.DayOfWeek % 7 == 0 ? 0 : (int)day.DayOfWeek));
}
/// <summary>
/// 获取两个日期之间相差的周数
/// </summary>
/// <param name="dt1"></param>
/// <param name="dt2"></param>
/// <returns></returns>
public static int GetWeekInBTime(DateTime dt1, DateTime dt2)
{
TimeSpan ts = dt1 - dt2;
DateTime dt = ts.TotalDays > 0 ? dt1 : dt2;
int days = (int)System.Math.Abs(ts.TotalDays) + (7 - ((int)dt.DayOfWeek + 1));
return days / 7 + (days % 7 == 0 ? 0 : 1);
}
补充:.NET技术 , ASP.NET