C# DateTime DateTime(Int32, Int32, Int32, Calendar)

Description

DateTime DateTime(Int32, Int32, Int32, Calendar) initializes a new instance of the DateTime structure to the specified year, month, and day for the specified calendar.

Syntax

DateTime.DateTime(Int32, Int32, Int32, Calendar) has the following syntax.


public DateTime(// ww  w .  j  a  va  2s.c om
  int year,
  int month,
  int day,
  Calendar calendar
)

Parameters

DateTime.DateTime(Int32, Int32, Int32, Calendar) has the following parameters.

  • year - The year (1 through the number of years in calendar).
  • month - The month (1 through the number of months in calendar).
  • day - The day (1 through the number of days in month).
  • calendar - The calendar that is used to interpret year, month, and day.

Example

The following example calls the DateTime(Int32, Int32, Int32, Calendar) constructor to instantiate DateTime values.


/*from  ww w  .ja  va 2s  . c  om*/
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;

public class Example
{
   public static void Main()
   {
      PersianCalendar persian = new PersianCalendar();
      DateTime date1 = new DateTime(1389, 5, 27, persian);
      Console.WriteLine(date1.ToString());
      Console.WriteLine("{0}/{1}/{2}\n", persian.GetMonth(date1), 
                                       persian.GetDayOfMonth(date1), 
                                       persian.GetYear(date1));

   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version