Calendar represents time in divisions, such as weeks, months, and years. : Calendar « Date Time « C# / C Sharp






Calendar represents time in divisions, such as weeks, months, and years.

 


using System;
using System.Globalization;


public class MainClass{

   public static void Main()  {

      // Sets a DateTime to April 13, 2010 of the Gregorian calendar.
      DateTime myDT = new DateTime( 2010, 4, 13, new GregorianCalendar() );

      // Uses the default calendar of the InvariantCulture.
      Calendar myCal = CultureInfo.InvariantCulture.Calendar;

      DisplayValues( myCal, myDT );

   }

   public static void DisplayValues( Calendar myCal, DateTime myDT )  {
      Console.WriteLine( "Era:          {0}", myCal.GetEra( myDT ) );
      Console.WriteLine( "Year:         {0}", myCal.GetYear( myDT ) );
      Console.WriteLine( "Month:        {0}", myCal.GetMonth( myDT ) );
      Console.WriteLine( "DayOfYear:    {0}", myCal.GetDayOfYear( myDT ) );
      Console.WriteLine( "DayOfMonth:   {0}", myCal.GetDayOfMonth( myDT ) );
      Console.WriteLine( "DayOfWeek:    {0}", myCal.GetDayOfWeek( myDT ) );
      Console.WriteLine( "Hour:         {0}", myCal.GetHour( myDT ) );
      Console.WriteLine( "Minute:       {0}", myCal.GetMinute( myDT ) );
      Console.WriteLine( "Second:       {0}", myCal.GetSecond( myDT ) );
      Console.WriteLine( "Milliseconds: {0}", myCal.GetMilliseconds( myDT ) );
   }

}

   
  








Related examples in the same category

1.Calendar ToDateTime is not culture aware
2.ToString(): make it culture aware
3.Two Digit Year Max
4.To Four Digit Year
5.Create date of 1/13/2009 using Hijri calendar and get Day property from DateTime
6.Add to year, month, week, day, hour, minute, second and millisecton
7.DateTime(Int32, Int32, Int32, Calendar): Create a DateTime structure to the specified year, month, and day for the specified calendar.
8.Using the Hijri Calendar
9.Using the Persian Calendar