DateTime 構造体の新しいインスタンスを、指定した暦の指定した年、月、および日に初期化します。
名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文
'宣言
Public Sub New ( _
year As Integer, _
month As Integer, _
day As Integer, _
calendar As Calendar _
)
'使用
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:
DateTime (
int year,
int month,
int day,
Calendar^ calendar
)
public DateTime (
int year,
int month,
int day,
Calendar calendar
)
public function DateTime (
year : int,
month : int,
day : int,
calendar : Calendar
)
パラメータ
- year
年 (1 から calendar の年数)。
- month
月 (1 から calendar の月数)。
- day
日付 (1 から month の日数)。
例外
例外の種類 | 条件 |
---|---|
calendar が null 参照 (Visual Basic では Nothing) です。 |
|
calendar の範囲外の値が year に指定されています。 または month が 1 未満か、calendar の月数よりも大きい値です。 または day が 1 未満か、month の月の日数よりも大きい値です。 |
|
解説
結果として得られた DateTime の時刻は深夜 (00:00:00) です。Kind プロパティは Unspecified に初期化されます。
year、month、および day に使用できる値は calendar によって異なります。calendar を使用して、指定した日付と時刻を表現できない場合にだけ、例外がスローされます。
System.Globalization 名前空間には、GregorianCalendar や JulianCalendar をなどの複数の暦が用意されています。
使用例
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