Example #1
0
        // 计算某个月有多少天
        private void GetLastDateForMonth(DateTime DtStart, out DateTime DtEnd)
        {
            int Dtyear, DtMonth;

            Dtyear  = DtStart.Year;
            DtMonth = DtStart.Month;
            int MonthCount = DateTime.DaysInMonth(Dtyear, DtMonth);//計算該月有多少天

            DtEnd = Convert.ToDateTime(Dtyear.ToString() + "-" + DtMonth.ToString() + "-" + MonthCount);
        }
Example #2
0
        /// <summary>
        ///   取得某月的最后一天
        ///   方法二:取出下月的第一天減去一天便是這個月的最后一天
        /// </summary>
        /// <param name="DtStart"> </param>
        /// <param name="DtEnd"> </param>
        public static void GetLastDateForMonthEx(DateTime DtStart, out DateTime DtEnd)
        {
            int Dtyear, DtMonth;

            DtStart = DateTime.Now.AddMonths(1); //月份加1
            Dtyear  = DtStart.Year;
            DtMonth = DtStart.Month;
            DtEnd   = Convert.ToDateTime(Dtyear.ToString() + "-" + DtMonth.ToString() + "-" + "1").AddDays(-1);
            //取出下月的第一天減去一天
        }
Example #3
0
        /// <summary>
        /// 获取月份的最后一天
        /// </summary>
        /// <param name="DayOfMonth">月份中的一天</param>
        /// <returns>该月的最后一天</returns>
        public static DateTime GetLastDateForMonth(DateTime DayOfMonth)
        {
            DateTime DtEnd;
            int      Dtyear, DtMonth;

            Dtyear  = DayOfMonth.Year;
            DtMonth = DayOfMonth.Month;
            int MonthCount = DateTime.DaysInMonth(Dtyear, DtMonth);//计算该月有多少天

            DtEnd = Convert.ToDateTime(Dtyear.ToString() + "-" + DtMonth.ToString() + "-" + MonthCount);
            DtEnd.AddDays(1).AddMilliseconds(-1);
            return(DtEnd);
        }