DateTime 構造体の新しいインスタンスを、指定した年、月、日、時、分、秒、およびミリ秒に初期化します。
名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文
'宣言
Public Sub New ( _
year As Integer, _
month As Integer, _
day As Integer, _
hour As Integer, _
minute As Integer, _
second As Integer, _
millisecond As Integer _
)
'使用
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
)
パラメータ
- year
年 (1 から 9999)。
- month
月 (1 から 12)。
- day
日付 (1 から month の日数)。
- hour
時間 (0 から 23)。
- minute
分 (0 から 59)。
- second
秒 (0 から 59)。
- millisecond
ミリ秒 (0 から 999)。
例外
例外の種類 | 条件 |
---|---|
year が 1 未満か、9999 よりも大きい値です。 または month が 1 未満か、12 よりも大きい値です。 または day が 1 未満か、month の月の日数よりも大きい値です。 または hour が 0 未満か、23 よりも大きい値です。 または minute が 0 未満か、59 よりも大きい値です。 または second が 0 未満か、59 よりも大きい値です。 または millisecond が 0 未満か、999 よりも大きい値です。 |
|
解説
Kind プロパティは Unspecified に初期化されます。
使用例
DateTime コンストラクタのコード例を次に示します。
' 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);
プラットフォーム
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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0