Create DateTime from year, month and day value - CSharp Language Basics

CSharp examples for Language Basics:Date Time

Description

Create DateTime from year, month and day value

Demo Code

using System;/*from w  w  w.j ava2 s  . c  om*/
class Program
{
   static void Main(string[] args)
   {
      // January 1, 2007:
      DateTime thisYear = new DateTime(2007, 1, 1);
      // Notice how you call IsLeapYear():
      Console.WriteLine("Is {0} a leap year? {1}", thisYear, DateTime.IsLeapYear(thisYear.Year));
      // February 29, 2008:
      DateTime nextYear = new DateTime(2008, 2, 29);
      Console.WriteLine("Is {0} a leap year? {1}", nextYear, DateTime.IsLeapYear(nextYear.Year));
   }
}

Result


Related Tutorials