[C # date series (1)] -- C # obtain 0 minutes 0 seconds on the first day of a month and 59 minutes and 59 seconds on the last day,

Source: Internet
Author: User

[C # date series (1)] -- C # obtain 0 minutes 0 seconds on the first day of a month and 59 minutes and 59 seconds on the last day,

You may encounter many uncommon requirements at work. For example, you need to obtain the first and last days of a month.

# Region get the first day of a month at 0 minutes 0 seconds /// <summary> /// get the first day of a month at 0 minutes 0 seconds /// </summary> /// <param name = "datetime"> to obtain a day of the month </param> /// <returns> </returns> public static DateTime FirstDayOfMonth (DateTime datetime) {return datetime. addMonths (-1 ). date. addDays (1-datetime. day ). addMonths (1 );} # endregion # region gets 59 minutes and 59 seconds on the last day of a month. // <summary> // gets 59 minutes and 59 seconds on the last day of a month. // </summary> /// <param name = "datetime"> obtain a day of the month </param> /// <returns> </returns> public static DateTime LastDayOfMonth (DateTime datetime) {return DateTime. parse (datetime. addDays (1-datetime. day ). addMonths (1 ). toShortDateString ()). addSeconds (-1) ;}# endregion

 

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.