C # Time operations

Source: Internet
Author: User
1. Take the last day of a month

1. Take the last day of a month
Method 1: calculate the number of days and years of the month. + Month + The number of days that can be added. For example, the last day of the month is used.

Private   Void Getlastdateformonth (datetime dtstart, Out Datetime dtend)
{
Int Dtyear, dtmonth;

Dtstart = Datetime. now;
Dtyear = Dtstart. Year;
Dtmonth = Dtstart. month;

Int Monthcount = Datetime. daysinmonth (dtyear, dtmonth );
Dtend = Convert. todatetime (dtyear. tostring () + " - " + Dtmonth. tostring () + " - " + Monthcount );

}

Method 2: retrieve the first day of next month minus one day is the last day.

Private   Void Getlastdateformonth (datetime dtstart, Out Datetime dtend)
{
Int Dtyear, dtmonth;

Dtstart = Datetime. Now. addmonths ( 1 );
Dtyear = Dtstart. Year;
Dtmonth = Dtstart. month;

Dtend = Convert. todatetime (dtyear. tostring () + " - " + Dtmonth. tostring () + " - " + " 1 " ). Adddays ( - 1 );

}

Method 1: calculate the number of days and years of the month.+Month+The number of days that can be added. For example, the last day of the month is used.

Method 2: retrieve the first day of next month minus one day is the last day.

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.