Month Of First Day - CSharp System

CSharp examples for System:DateTime Month

Description

Month Of First Day

Demo Code


using System.Globalization;
using System.Text.RegularExpressions;
using System.Web;
using System.Linq;
using System.Collections.Generic;
using System;/*from ww  w .  ja  va  2 s .  c  o  m*/

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

Related Tutorials