This example describes how C # obtains the first and last day dates of the previous month. Share to everyone for your reference.
The specific implementation code is as follows:
The code is as follows:
int year = datetime.now.year;//when the year before last
int mouth = datetime.now.month;//Current Month
int beforeyear = 0;
int beforemouth = 0;
if (mouth <= 1)//If the current month is January, then the year will be reduced by 1
{
Beforeyear = year–1;
Beforemouth =12;//last month
}
Else
{
Beforeyear = year;
Beforemouth = mouth–1;//Last month
}
String beforemouthoneday = Beforeyear + "Year" + Beforemouth + "Month" + 1 + "day";//first day of last month
String beforemouthlastday = Beforeyear + "Year" + Beforemouth + "month" + datetime.daysinmonth (year, Beforemouth) + "Day";//Last Day of last month
The last day of last month can also be written like this:
The code is as follows:
String beforemouthlastday = DateTime.Parse (DateTime.Now.ToString ("yyyy-mm-01")). AddDays (-1). ToString ("Yyyy-mm-dd"); Get the last day of the month date
I hope this article is helpful to everyone's C # programming.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
C # Get the first day and last day of the month date method
This address: http://www.paobuke.com/develop/c-develop/pbk23311.html
Related content C # using Itextsharp to add PDF watermarks to the differences between C + + reference & and pointers when used as formal parameters why is hash access relatively fast? What it takes to use it. C # Implementation method of deleting a row based on conditions in a DataTable
C#dt?? Iis?? Μ?framework°?±@@facesymbol@@μ?? ¨c# using Itextsharp to get content from a PDF document C # Implementation of the picture, string mutual conversion class share C # Implementation simple get and set session class
C # Get the first day and last day of the month date method