C # Get the first day and last day of the month date method

Source: Internet
Author: User

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 &amp; 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.