How many days are there in the current month
</summary>
<param name= "Y" ></param>
<param name= "M" ></param>
<returns></returns>
public static int Howmonthday (int y, int m)
{
int mnext;
int ynext;
if (M < 12)
{
Mnext = m + 1;
Ynext = y;
}
Else
{
Mnext = 1;
Ynext = y + 1;
}
DateTime dt1 = System.Convert.ToDateTime (y + "-" + M + "-1");
DateTime DT2 = System.Convert.ToDateTime (Ynext + "-" + Mnext + "-1");
TimeSpan diff = dt2-dt1;
Return diff. Days;
}
/**////<summary>
Get the start date and deadline of a week in a year
Year Nyear
Week number Nnumweek
Week start out Dtweekstart
Week End out Dtweekeend
</summary>
<param name= "Nyear" ></param>
<param name= "Nnumweek" ></param>
<param name= "Dtweekstart" ></param>
<param name= "Dtweekeend" ></param>
public static void Getweek (int nyear, int. Nnumweek, Out datetime dtweekstart, out datetime dtweekeend)
{
DateTime dt = new DateTime (Nyear, 1, 1);
DT = dt + new TimeSpan ((nNumWeek-1) * 7, 0, 0, 0);
Dtweekstart = dt. AddDays (-(int) dt. DayOfWeek + (int) dayofweek.monday);
dtweekeend = dt. AddDays ((int) dayofweek.saturday-(int) dt. DayOfWeek + 1);
}
/**////<summary>
///How many weeks in a year
//return int
//</summary>
//<param name= "Stryear" ></ Param>
//<returns>int</returns>
public static int getyearweekcount (int stryear)
{
string returnstr = "";
System.DateTime fDt = DateTime.Parse ( Stryear.tostring () + "01-01");
int k = Convert.ToInt32 (Fdt.dayofweek);// The first day of the year is the of the week;
if (k = = 1)
{
int countday = fdt.addyears (1). AddDays (-1). DayOfYear;
int countweek = COUNTDAY/7 + 1;
return countweek;
}
Else
{
int countday = Fdt.addyears (1). AddDays (-1). DayOfYear;
int Countweek = COUNTDAY/7 + 2;
return countweek;
}
}
/**////<summary>
Ask the current date is the first week of the year
</summary>
<param name= "Date" ></param>
<returns></returns>
public static int WeekOfYear (DateTime curday)
{
int firstdayofweek = Convert.ToInt32 (Convert.todatetime (curDay.Year.ToString () + "-" + "1-1"). DayOfWeek);
int days = Curday.dayofyear;
int daysoutoneweek = days-(7-firstdayofweek);
if (daysoutoneweek <= 0)
{
return 1;
}
Else
{
int weeks = DAYSOUTONEWEEK/7;
if ( Daysoutoneweek% 7! = 0)
weeks++;
return weeks + 1;
}
}
C # Calculation of the date and month days and the number of weeks in a year and the time period obtained by a certain week of the year