获得当前年的天数
int yeardays = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInYear(DateTime.Now.Year);
获取当前年的周数
/// <summary>
/// 获得今年有几周
/// </summary>
/// <param name="year"></param>
/// <returns></returns>
public int GetWeekOfYear(int year)
{
DateTime the_Date = newDateTime(year,1,1);//本年的第一天
TimeSpantt=the_Date.AddYears(1)-the_Date;//求出本年有几天
return tt.Days / 7 + 1; //因为年只有366天和365天除以7有余数所以始终需要加一周
}
获取当前月的天数
第一种:
DateTime dtNow = DateTime.Now;
int days =DateTime.DaysInMonth(dtNow.Year ,dtNow.Month);
第二种:
intdays=System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(DateTime.Now.Year,DateTime.Now.Month);
第三种:
DateTimedtNow = DateTime.Today;
int days =dtNow .AddDays(1 - dtNow .Day).AddMonths(1).AddDays(-1).Day;