Month Of Last Day - CSharp System

CSharp examples for System:DateTime Month

Description

Month Of Last Day

Demo Code


using System.Globalization;
using System.Text.RegularExpressions;
using System.Web;
using System.Linq;
using System.Collections.Generic;
using System;//ww  w .ja v a  2s  . c om

public class Main{
            public static DateTime MonthOfLastDay(int year, int month)
            {
                if (year <= 0001 || year >= 9999) return DateTime.MaxValue;
                if (month < 1 || month > 12) return DateTime.MaxValue;
                DateTime result = DateTime.MaxValue;
                string tmpString = string.Format("{0}-{1}-{2}", year, month, DateTime.DaysInMonth(year, month));
                DateTime.TryParse(tmpString, out result);
                return result;
            }
            public static DateTime MonthOfLastDay()
            {
                DateTime _now = DateTime.Now;
                return MonthOfLastDay(_now.Year, _now.Month);
            }
}

Related Tutorials