[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