Asp.net C # obtain the last day of the previous month of the current month.

Source: Internet
Author: User

Original http://blog.csdn.net/summer_dream_journey/article/details/8998338

The project is used, so it is fully written for reference.

 

[Csharp]View plaincopyprint?
    1. DateTime dt = DateTime. Now;
    2. Int weeknow = Convert. ToInt32 (DateTime. Now. DayOfWeek );
    3. Int dayspan = (-1) * weeknow + 1;
    4. DateTime dt2 = dt. AddMonths (1 );
    5. // Obtain the first day of the week
    6. This. Label1.Text = DateTime. Now. AddDays (dayspan). ToString ("yyyy-MM-dd ");
    7. // The first day of the month
    8. This. Label1.Text = dt. AddDays (-(dt. Day) + 1). ToString ("yyyy-MM-dd ");
    9. // Last day of the month
    10. This. Label1.Text = dt2.AddDays (-dt. Day). ToString ("yyyy-MM-dd ");
    11. // The first day of last month
    12. This. Label1.Text = dt. AddMonths (-1). AddDays (-dt. Day + 1). ToString ("yyyy-MM-dd ");
    13. // Last day of last month
    14. This. Label1.Text = dt. AddDays (-dt. Day). ToString ("yyyy-MM-dd ");
    15. // The first day of the previous year
    16. This. label1.Text = dt. addYears (-1 ). addMonths (-dt. month + 1 ). addDays (-dt. day + 1 ). toString ("yyyy-MM-dd ");
    17. // Last day of the previous year
    18. This. Label1.Text = dt. AddMonths (-dt. Month + 1). AddDays (-dt. Day). ToString ("yyyy-MM-dd ");
    19. // The first day of this year
    20. This. Label1.Text = dt. AddMonths (-dt. Month + 1). AddDays (-dt. Day + 1). ToString ("yyyy-MM-dd ");
    21. // The first day of last week
    22. This. Label1.Text = DateTime. Now. AddDays (daydiff-7). ToString ("yyyy-MM-dd ");
    23. // Last day of last week
    24. This. Label1.Text = DateTime. Now. AddDays (daydiff-1). ToString ("yyyy-MM-dd ");

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.