Export (0) Print
Expand All
8 out of 16 rated this helpful - Rate this topic

DateTime Constructor

.NET Framework 1.1

Initializes a new instance of the DateTime structure.

Overload List

Initializes a new instance of the DateTime structure to a specified number of ticks.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(Long)
[C#] public DateTime(long);
[C++] public: DateTime(__int64);
[JScript] public function DateTime(long);

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

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(Integer, Integer, Integer)
[C#] public DateTime(int, int, int);
[C++] public: DateTime(int, int, int);
[JScript] public function DateTime(int, int, int);

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

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(Integer, Integer, Integer, Calendar)
[C#] public DateTime(int, int, int, Calendar);
[C++] public: DateTime(int, int, int, Calendar*);
[JScript] public function DateTime(int, int, int, Calendar);

Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, and second.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(Integer, Integer, Integer, Integer, Integer, Integer)
[C#] public DateTime(int, int, int, int, int, int);
[C++] public: DateTime(int, int, int, int, int, int);
[JScript] public function DateTime(int, int, int, int, int, int);

Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, and second for the specified Calendar.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(Integer, Integer, Integer, Integer, Integer, Integer, Calendar)
[C#] public DateTime(int, int, int, int, int, int, Calendar);
[C++] public: DateTime(int, int, int, int, int, int, Calendar*);
[JScript] public function DateTime(int, int, int, int, int, int, Calendar);

Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and millisecond.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(Integer, Integer, Integer, Integer, Integer, Integer, Integer)
[C#] public DateTime(int, int, int, int, int, int, int);
[C++] public: DateTime(int, int, int, int, int, int, int);
[JScript] public function DateTime(int, int, int, int, int, int, int);

Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and millisecond for the specified Calendar.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(Integer, Integer, Integer, Integer, Integer, Integer, Integer, Calendar)
[C#] public DateTime(int, int, int, int, int, int, int, Calendar);
[C++] public: DateTime(int, int, int, int, int, int, int, Calendar*);
[JScript] public function DateTime(int, int, int, int, int, int, int, Calendar);

Example

[Visual Basic, C#, C++] The following sample demonstrates one of the DateTime constructors.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the DateTime constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' 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)

[C#] 
// 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.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);

[C++] 
// 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(S"en-US", false);

System::Globalization::Calendar* calendar = info->Calendar;

System::DateTime dateTime = 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(S"{0:F}", __box(dateTime));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DateTime Structure | DateTime Members | System Namespace

Show:
© 2014 Microsoft. All rights reserved.