DateTime コンストラクタとは? わかりやすく解説

DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32)

DateTime 構造体新しインスタンスを、指定した年、月、日、時、分、および秒に初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

year1 未満か、9999 よりも大きい値です。

または

month1 未満か、12 よりも大きい値です。

または

day1 未満か、month の月の日数よりも大きい値です。

または

hour が 0 未満か、23 よりも大きい値です。

または

minute が 0 未満か、59 よりも大きい値です。

または

second が 0 未満か、59 よりも大きい値です。

ArgumentException

指定したパラメータが、MinValue 未満、または MaxValue よりも大きいと評価されました。

解説解説
使用例使用例

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);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, Int32)

DateTime 構造体新しインスタンスを、指定した年、月、日、時、分、秒、およびミリ秒初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

year1 未満か、9999 よりも大きい値です。

または

month1 未満か、12 よりも大きい値です。

または

day1 未満か、month の月の日数よりも大きい値です。

または

hour が 0 未満か、23 よりも大きい値です。

または

minute が 0 未満か、59 よりも大きい値です。

または

second が 0 未満か、59 よりも大きい値です。

または

millisecond が 0 未満か、999 よりも大きい値です。

ArgumentException

指定したパラメータが、MinValue 未満、または MaxValue よりも大きいと評価されました。

解説解説
使用例使用例

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);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime コンストラクタ (Int32, Int32, Int32)

DateTime 構造体新しインスタンスを、指定した年、月、および日に初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

year1 未満か、9999 よりも大きい値です。

または

month1 未満か、12 よりも大きい値です。

または

day1 未満か、month の月の日数よりも大きい値です。

ArgumentException

指定したパラメータが、MinValue 未満、または MaxValue よりも大きいと評価されました。

解説解説
使用例使用例

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);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime コンストラクタ (Int64)

DateTime 構造体新しインスタンスを、指定したタイマ刻み数に初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

ticks が MinValue より小さい値か、MaxValue より大きい値です。

解説解説
使用例使用例

DateTime コンストラクタコード例次に示します

' This example demonstrates the DateTime(Int64) constructor.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Class Sample
   Public Shared Sub Main()
      ' Instead of using the implicit, default "G" date and
 time format string, we 
      ' use a custom format string that aligns the results and inserts
 leading zeroes.
      Dim format As String
 = "{0}) The {1} date and time is {2:MM/dd/yyyy hh:mm:ss tt}"
      
      ' Create a DateTime for the maximum date and time using ticks.
      Dim dt1 As New DateTime(DateTime.MaxValue.Ticks)
      
      ' Create a DateTime for the minimum date and time using ticks.
      Dim dt2 As New DateTime(DateTime.MinValue.Ticks)
      
      ' Create a custom DateTime for 7/28/1979 at 10:35:05 PM using
 a 
      ' calendar based on the "en-US" culture, and ticks.
 
      Dim ticks As Long
 = New DateTime(1979, 7, 28, 22, 35, 5, _
                                       New CultureInfo("en-US",
 False).Calendar).Ticks
      Dim dt3 As New DateTime(ticks)
      
      Console.WriteLine(format, 1, "maximum", dt1)
      Console.WriteLine(format, 2, "minimum", dt2)
      Console.WriteLine(format, 3, "custom ", dt3)
      Console.WriteLine(vbCrLf & "The custom date and time
 is created from {0:N0} ticks.", ticks)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'1) The maximum date and time is 12/31/9999 11:59:59 PM
'2) The minimum date and time is 01/01/0001 12:00:00 AM
'3) The custom  date and time is 07/28/1979 10:35:05 PM
'
'The custom date and time is created from 624,376,461,050,000,000 ticks.
'
// This example demonstrates the DateTime(Int64) constructor.
using System;
using System.Globalization;

class Sample 
{
    public static void Main()
 
    {
// Instead of using the implicit, default "G" date and time
 format string, we 
// use a custom format string that aligns the results and inserts leading
 zeroes.
    string format = "{0}) The {1} date and time is {2:MM/dd/yyyy
 hh:mm:ss tt}";

// Create a DateTime for the maximum date and time using ticks.
    DateTime dt1 = new DateTime(DateTime.MaxValue.Ticks);

// Create a DateTime for the minimum date and time using ticks.
    DateTime dt2 = new DateTime(DateTime.MinValue.Ticks);

// Create a custom DateTime for 7/28/1979 at 10:35:05 PM using a 
// calendar based on the "en-US" culture, and ticks. 
    long ticks = new DateTime(1979, 07, 28, 22, 35, 5, 
    new CultureInfo("en-US", false).Calendar).Ticks;
    DateTime dt3 = new DateTime(ticks);

    Console.WriteLine(format, 1, "maximum", dt1);
    Console.WriteLine(format, 2, "minimum", dt2);
    Console.WriteLine(format, 3, "custom ", dt3);
    Console.WriteLine("\nThe custom date and time is created from {0:N0} ticks.",
 ticks);
    }
}
/*
This example produces the following results:

1) The maximum date and time is 12/31/9999 11:59:59 PM
2) The minimum date and time is 01/01/0001 12:00:00 AM
3) The custom  date and time is 07/28/1979 10:35:05 PM

The custom date and time is created from 624,376,461,050,000,000 ticks.

*/
// This example demonstrates the DateTime(Int64) constructor.
using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Instead of using the implicit, default "G" date and time
 format string, we 
   // use a custom format string that aligns the results and inserts leading
 zeroes.
   String^ format = "{0}) The {1} date and time is {2:MM/dd/yyyy hh:mm:ss tt}";
   
   // Create a DateTime for the maximum date and time using ticks.
   DateTime dt1 = DateTime(DateTime::MaxValue.Ticks);
   
   // Create a DateTime for the minimum date and time using ticks.
   DateTime dt2 = DateTime(DateTime::MinValue.Ticks);
   
   // Create a custom DateTime for 7/28/1979 at 10:35:05 PM using a
 
   // calendar based on the "en-US" culture, and ticks. 
   Int64 ticks = DateTime(1979,07,28,22,35,5,(gcnew CultureInfo( "en-US",false
 ))->Calendar).Ticks;
   DateTime dt3 = DateTime(ticks);
   Console::WriteLine( format, 1, "maximum", dt1 );
   Console::WriteLine( format, 2, "minimum", dt2 );
   Console::WriteLine( format, 3, "custom ", dt3 );
   Console::WriteLine( "\nThe custom date and time is created from {0:N0} ticks.",
 ticks );
}

/*
This example produces the following results:

1) The maximum date and time is 12/31/9999 11:59:59 PM
2) The minimum date and time is 01/01/0001 12:00:00 AM
3) The custom  date and time is 07/28/1979 10:35:05 PM

The custom date and time is created from 624,376,461,050,000,000 ticks.

*/
// This example demonstrates the DateTime(Int64) constructor.
import System.*;
import System.Globalization.*;

class Sample
{
    public static void main(String[]
 args)
    {
        // Instead of using the implicit, default "G" date
 and time 
        // format string, we use a custom format string that aligns
 
        // the results and inserts leading zeroes.
        String format = "{0}) The {1} date and time is "
            + "{2:MM/dd/yyyy hh:mm:ss tt}";
        // Create a DateTime for the maximum date and time using ticks.
        DateTime dt1 = new DateTime(DateTime.MaxValue.get_Ticks());
        // Create a DateTime for the minimum date and time using ticks.
        DateTime dt2 = new DateTime(DateTime.MinValue.get_Ticks());
        // Create a custom DateTime for 7/28/1979 at 10:35:05 PM using a
 
        // calendar based on the "en-US" culture, and ticks.
 
        long ticks = (new DateTime(1979, 7, 28, 22, 35, 5, 
             (new CultureInfo("en-US", false)).get_Calendar())).get_Ticks();
        DateTime dt3 = new DateTime(ticks);

        Console.WriteLine(format, (Int32)1, "maximum", dt1);
        Console.WriteLine(format, (Int32)2, "minimum", dt2);
        Console.WriteLine(format, (Int32)3, "custom ", dt3);
        Console.WriteLine("\nThe custom date and time is "
            + "created from {0:N0} ticks.", (Int64)ticks);
    } //main
} //Sample
/*
This example produces the following results:

1) The maximum date and time is 12/31/9999 11:59:59 PM
2) The minimum date and time is 01/01/0001 12:00:00 AM
3) The custom  date and time is 07/28/1979 10:35:05 PM

The custom date and time is created from 624,376,461,050,000,000 ticks.

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, Calendar)

DateTime 構造体新しインスタンスを、指定した暦の指定した年、月、日、時、分、および秒に初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

calendarnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

calendar範囲外の値が year指定されています。

または

month1 未満か、calendar月数よりも大きい値です。

または

day1 未満か、month の月の日数よりも大きい値です。

または

hour が 0 未満か、23 よりも大きい値です。

または

minute が 0 未満か、59 よりも大きい値です。

または

second が 0 未満か、59 よりも大きい値です。

ArgumentException

指定したパラメータが、MinValue 未満、または MaxValue よりも大きいと評価されました。

解説解説
使用例使用例

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);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

DateTime 構造体新しインスタンスを、特定の暦の指定した年、月、日、時、分、秒、ミリ秒、および世界協定時刻 (UTC) または現地時刻初期化します。

名前空間: 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, _
    calendar As Calendar, _
    kind As DateTimeKind _
)

パラメータ

year

年 (1 から calendar年数)。

month

月 (1 から calendar月数)。

day

日付 (1 から month日数)。

hour

時間 (0 から 23)。

minute

分 (0 から 59)。

second

秒 (0 から 59)。

millisecond

ミリ秒 (0 から 999)。

calendar

DateTime適用する Calendar

kind

yearmonthdayhourminutesecondmillisecond現地時刻である、世界協定時刻 (UTC) である、またはそのどちらでもないことを指定する DateTimeKind 値。

例外例外
例外種類条件

ArgumentNullException

calendarnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

calendar範囲外の値が year指定されています。

または

month1 未満か、calendar月数よりも大きい値です。

または

day1 未満か、month の月の日数よりも大きい値です。

または

hour が 0 未満か、23 よりも大きい値です。

または

minute が 0 未満か、59 よりも大きい値です。

または

second が 0 未満か、59 よりも大きい値です。

または

millisecond が 0 未満か、999 よりも大きい値です。

ArgumentException

指定したパラメータが、MinValue 未満、または MaxValue よりも大きいと評価されました。

または

kindDateTimeKind 値ではありません。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar)

DateTime 構造体新しインスタンスを、指定した暦の指定した年、月、日、時、分、秒、およびミリ秒初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

calendarnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

calendar範囲外の値が year指定されています。

または

month1 未満か、calendar月数よりも大きい値です。

または

day1 未満か、month の月の日数よりも大きい値です。

または

hour が 0 未満か、23 よりも大きい値です。

または

minute が 0 未満か、59 よりも大きい値です。

または

second が 0 未満か、59 よりも大きい値です。

または

millisecond が 0 未満か、999 よりも大きい値です。

ArgumentException

指定したパラメータが、MinValue 未満、または MaxValue よりも大きいと評価されました。

解説解説
使用例使用例

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);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

DateTime 構造体新しインスタンスを、指定した年、月、日、時、分、秒、ミリ秒、および世界協定時刻 (UTC) または現地時刻初期化します。

名前空間: 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, _
    kind As DateTimeKind _
)

パラメータ

year

年 (1 から 9999)。

month

月 (1 から 12)。

day

日付 (1 から month日数)。

hour

時間 (0 から 23)。

minute

分 (0 から 59)。

second

秒 (0 から 59)。

millisecond

ミリ秒 (0 から 999)。

kind

yearmonthdayhourminutesecondmillisecond現地時刻である、世界協定時刻 (UTC) である、またはそのどちらでもないことを指定する DateTimeKind 値。

例外例外
例外種類条件

ArgumentOutOfRangeException

year1 未満か、9999 よりも大きい値です。

または

month1 未満か、12 よりも大きい値です。

または

day1 未満か、month の月の日数よりも大きい値です。

または

hour が 0 未満か、23 よりも大きい値です。

または

minute が 0 未満か、59 よりも大きい値です。

または

second が 0 未満か、59 よりも大きい値です。

または

millisecond が 0 未満か、999 よりも大きい値です。

ArgumentException

指定したパラメータが、MinValue 未満、または MaxValue よりも大きいと評価されました。

または

kindDateTimeKind 値ではありません。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime コンストラクタ (Int32, Int32, Int32, Calendar)

DateTime 構造体新しインスタンスを、指定した暦の指定した年、月、および日に初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

calendarnull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

calendar範囲外の値が year指定されています。

または

month1 未満か、calendar月数よりも大きい値です。

または

day1 未満か、month の月の日数よりも大きい値です。

ArgumentException

指定したパラメータが、MinValue 未満、または MaxValue よりも大きいと評価されました。

解説解説
使用例使用例

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);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime コンストラクタ

DateTime 構造体新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
DateTime (Int64) DateTime 構造体新しインスタンスを、指定したタイマ刻み数に初期化します。

.NET Compact Framework によってサポートされています。

DateTime (Int64, DateTimeKind) DateTime 構造体新しインスタンスを、指定したタイマ刻み数と世界協定時刻 (UTC) または現地時刻初期化します。

.NET Compact Framework によってサポートされています。

DateTime (Int32, Int32, Int32) DateTime 構造体新しインスタンスを、指定した年、月、および日に初期化します。

.NET Compact Framework によってサポートされています。

DateTime (Int32, Int32, Int32, Calendar) DateTime 構造体新しインスタンスを、指定した暦の指定した年、月、および日に初期化します。

.NET Compact Framework によってサポートされています。

DateTime (Int32, Int32, Int32, Int32, Int32, Int32) DateTime 構造体新しインスタンスを、指定した年、月、日、時、分、および秒に初期化します。

.NET Compact Framework によってサポートされています。

DateTime (Int32, Int32, Int32, Int32, Int32, Int32, Calendar) DateTime 構造体新しインスタンスを、指定した暦の指定した年、月、日、時、分、および秒に初期化します。

.NET Compact Framework によってサポートされています。

DateTime (Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind) DateTime 構造体新しインスタンスを、指定した年、月、日、時、分、秒、および世界協定時刻 (UTC) または現地時刻初期化します。

.NET Compact Framework によってサポートされています。

DateTime (Int32, Int32, Int32, Int32, Int32, Int32, Int32) DateTime 構造体新しインスタンスを、指定した年、月、日、時、分、秒、およびミリ秒初期化します。

.NET Compact Framework によってサポートされています。

DateTime (Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar) DateTime 構造体新しインスタンスを、指定した暦の指定した年、月、日、時、分、秒、およびミリ秒初期化します。

.NET Compact Framework によってサポートされています。

DateTime (Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind) DateTime 構造体新しインスタンスを、指定した年、月、日、時、分、秒、ミリ秒、および世界協定時刻 (UTC) または現地時刻初期化します。

.NET Compact Framework によってサポートされています。

DateTime (Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind) DateTime 構造体新しインスタンスを、特定の暦の指定した年、月、日、時、分、秒、ミリ秒、および世界協定時刻 (UTC) または現地時刻初期化します。

.NET Compact Framework によってサポートされています。

参照参照

DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

DateTime 構造体新しインスタンスを、指定した年、月、日、時、分、秒、および世界協定時刻 (UTC) または現地時刻初期化します。

名前空間: 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, _
    kind As DateTimeKind _
)
public function DateTime (
    year : int, 
    month : int, 
    day : int, 
    hour : int, 
    minute : int, 
    second : int, 
    kind : DateTimeKind
)

パラメータ

year

年 (1 から 9999)。

month

月 (1 から 12)。

day

日付 (1 から month日数)。

hour

時間 (0 から 23)。

minute

分 (0 から 59)。

second

秒 (0 から 59)。

kind

yearmonthdayhourminutesecond現地時刻である、世界協定時刻 (UTC) である、またはそのどちらでもないことを指定する DateTimeKind 値。

例外例外
例外種類条件

ArgumentOutOfRangeException

year1 未満か、9999 よりも大きい値です。

または

month1 未満か、12 よりも大きい値です。

または

day1 未満か、month の月の日数よりも大きい値です。

または

hour が 0 未満か、23 よりも大きい値です。

または

minute が 0 未満か、59 よりも大きい値です。

または

second が 0 未満か、59 よりも大きい値です。

ArgumentException

指定したパラメータが、MinValue 未満、または MaxValue よりも大きいと評価されました。

または

kindDateTimeKind 値ではありません。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime コンストラクタ (Int64, DateTimeKind)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

DateTime 構造体新しインスタンスを、指定したタイマ刻み数と世界協定時刻 (UTC) または現地時刻初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    ticks As Long, _
    kind As DateTimeKind _
)
Dim ticks As Long
Dim kind As DateTimeKind

Dim instance As New DateTime(ticks,
 kind)
public DateTime (
    long ticks,
    DateTimeKind kind
)
public:
DateTime (
    long long ticks, 
    DateTimeKind kind
)
public DateTime (
    long ticks, 
    DateTimeKind kind
)
public function DateTime (
    ticks : long, 
    kind : DateTimeKind
)

パラメータ

ticks

100 ナノ秒単位表され日付と時刻

kind

ticks現地時刻である、世界協定時刻 (UTC) である、またはそのどちらでもないことを指定する DateTimeKind 値。

例外例外
例外種類条件

ArgumentOutOfRangeException

ticks が MinValue より小さい値か、MaxValue より大きい値です。

ArgumentException

kindDateTimeKind 値ではありません。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DateTime コンストラクタ」の関連用語

DateTime コンストラクタのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DateTime コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS