最近在寫報表的東西,在網路上看到取得目前的日期是第幾週和該年有幾週的函數
首先要 using System.Globalization;
//取得目前週數
public int GetWeekOfYear(DateTime dt)
{
GregorianCalendar GetWeek= new GregorianCalendar();
return GetWeek.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
}
//取得該年有多少週
public int GetWeekAmount(int year)
{
DateTime end = new DateTime(year, 12, 31); //該年最後一天
System.Globalization.GregorianCalendar gc = new GregorianCalendar();
return gc.GetWeekOfYear(end, CalendarWeekRule.FirstDay, DayOfWeek.Monday); //該年的週數
}
全站熱搜
留言列表