DateTime-Konstruktor (Int32, Int32, Int32, Int32, Int32, Int32, Int32)
Initialisiert eine neue Instanz der DateTime-Struktur mit den angegebenen Werten für Jahr, Monat, Tag, Stunde, Minute, Sekunde und Millisekunde.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Sub New ( _
year As Integer, _
month As Integer, _
day As Integer, _
hour As Integer, _
minute As Integer, _
second As Integer, _
millisecond As Integer _
)
'Usage
Dim year As Integer
Dim month As Integer
Dim day As Integer
Dim hour As Integer
Dim minute As Integer
Dim second As Integer
Dim millisecond As Integer
Dim instance As New DateTime(year, month, day, hour, minute, second, millisecond)
public DateTime (
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond
)
public:
DateTime (
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond
)
public DateTime (
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond
)
public function DateTime (
year : int,
month : int,
day : int,
hour : int,
minute : int,
second : int,
millisecond : int
)
Parameter
- year
Das Jahr (1 bis 9999).
- month
Der Monat (1 bis 12).
- day
Der Tag (1 bis zur Anzahl der Tage in month).
- hour
Die Stunden (0 bis 23).
- minute
Die Minuten (0 bis 59).
- second
Die Sekunden (0 bis 59).
- millisecond
Die Millisekunden (0 bis 999).
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
year ist kleiner als 1 oder größer als 9999. – oder – month ist kleiner als 1 oder größer als 12. – oder – day ist kleiner als 1 oder größer als die Anzahl der Tage in month. – oder – hour ist kleiner als 0 oder größer als 23. – oder – minute ist kleiner als 0 oder größer als 59. – oder – second ist kleiner als 0 oder größer als 59. – oder – millisecond ist kleiner als 0 oder größer als 999. |
|
Die angegebenen Parameter ergeben einen Wert, der kleiner als MinValue oder größer als MaxValue ist. |
Hinweise
Die Kind-Eigenschaft wird mit Unspecified initialisiert.
Beispiel
Im folgenden Codebeispiel wird die Verwendung eines der DateTime-Konstruktoren veranschaulicht.
' 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.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);
// 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 =
gcnew System::Globalization::CultureInfo( "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( "{0:F}", dateTime );
// 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);
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0