Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DateTime Constructor (Int32, Int32, Int32, Calendar)

Initializes a new instance of the DateTime structure to the specified year, month, and day for the specified calendar.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

'Declaration
Public Sub New ( _
	year As Integer, _
	month As Integer, _
	day As Integer, _
	calendar As Calendar _
)
'Usage
Dim year As Integer
Dim month As Integer
Dim day As Integer
Dim calendar As Calendar

Dim instance As New DateTime(year, month, day, calendar)
public DateTime (
	int year, 
	int month, 
	int day, 
	Calendar calendar
)
public function DateTime (
	year : int, 
	month : int, 
	day : int, 
	calendar : Calendar
)

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 applies to this DateTime.

Exception typeCondition

ArgumentNullException

calendar is a null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

year is not in the range supported by calendar.

-or-

month is less than 1 or greater than the number of months in calendar.

-or-

day is less than 1 or greater than the number of days in month.

ArgumentException

Specified parameters evaluate to less than MinValue or more than MaxValue.

The time of day for the resulting DateTime is midnight (00:00:00). The Kind property is initialized to Unspecified.

The allowable values for year, month, and day depend on calendar. An exception is thrown if the specified date and time cannot be expressed using calendar.

The System.Globalization namespace provides several calendars including GregorianCalendar and JulianCalendar.

The following code example demonstrates one of the DateTime constructors.

' Create a new instance of DateTime containing the date 
   ' 7/28/1979 at 10:35:05 PM using the en-US calendar.
Dim info As New System.Globalization.CultureInfo("en-US", false)
   Dim cal As System.Globalization.Calendar
cal = info.Calendar

Dim myDateTime As New System.DateTime(1979, 7, 28, 22, 35, _
                                      5, 15, cal)

' Write the DateTime as "Saturday, July 28, 1979 10:35:05 PM".
System.Console.WriteLine("{0:F}", myDateTime)

// Create a new instance of DateTime containing the date 
// 7/28/1979 at 10:35:05 PM using the en-US calendar.
System.Globalization.CultureInfo info = new System.Globalization.
    CultureInfo("en-US", false);
System.Globalization.Calendar calendar = info.get_Calendar();
System.DateTime dateTime = new System.DateTime(
    1979,    // Year
    07,      // Month
    28,      // Day
    22,      // Hour
    35,      // Minute
    5,       // Second
    15,      // Millisecond
    calendar // Calendar
    );
// Write the DateTime as "Saturday, July 28, 1979 10:35:05 PM".
System.Console.WriteLine("{0:F}", dateTime);

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft