datetime 記述の変更が発生した日付を指定する
DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32)
アセンブリ: mscorlib (mscorlib.dll 内)

Public Sub New ( _ year As Integer, _ month As Integer, _ day As Integer, _ hour As Integer, _ minute As Integer, _ second 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 instance As New DateTime(year, month, day, hour, minute, second)
public function DateTime ( year : int, month : int, day : int, hour : int, minute : int, second : int )



' 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, Int32)
アセンブリ: 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 function DateTime ( year : int, month : int, day : int, hour : int, minute : int, second : int, millisecond : int )



' 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DateTime コンストラクタ (Int32, Int32, Int32)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim year As Integer Dim month As Integer Dim day As Integer Dim instance As New DateTime(year, month, day)



' 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DateTime コンストラクタ (Int64)
アセンブリ: mscorlib (mscorlib.dll 内)




' 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. */

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, Calendar)
アセンブリ: mscorlib (mscorlib.dll 内)

Public Sub New ( _ year As Integer, _ month As Integer, _ day As Integer, _ hour As Integer, _ minute As Integer, _ second As Integer, _ calendar As Calendar _ )
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 calendar As Calendar Dim instance As New DateTime(year, month, day, hour, minute, second, calendar)
public DateTime ( int year, int month, int day, int hour, int minute, int second, Calendar calendar )
public: DateTime ( int year, int month, int day, int hour, int minute, int second, Calendar^ calendar )
public DateTime ( int year, int month, int day, int hour, int minute, int second, Calendar calendar )
public function DateTime ( year : int, month : int, day : int, hour : int, minute : int, second : int, calendar : Calendar )


Kind プロパティは Unspecified に初期化されます。
year、month、および day に使用できる値は calendar によって異なります。calendar を使用して、指定した日付と時刻を表現できない場合にだけ、例外がスローされます。
System.Globalization 名前空間には、GregorianCalendar や JulianCalendar をなどの複数の暦が用意されています。

' 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind)
アセンブリ: 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 _ )
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 calendar As Calendar Dim kind As DateTimeKind Dim instance As New DateTime(year, month, day, hour, minute, second, millisecond, calendar, kind)
public DateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, DateTimeKind kind )
public: DateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar^ calendar, DateTimeKind kind )
public DateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, DateTimeKind kind )
public function DateTime ( year : int, month : int, day : int, hour : int, minute : int, second : int, millisecond : int, calendar : Calendar, kind : DateTimeKind )

例外の種類 | 条件 |
---|---|
ArgumentNullException | calendar が null 参照 (Visual Basic では Nothing) です。 |
ArgumentOutOfRangeException | calendar の範囲外の値が year に指定されています。 または month が 1 未満か、calendar の月数よりも大きい値です。 または day が 1 未満か、month の月の日数よりも大きい値です。 または または または または millisecond が 0 未満か、999 よりも大きい値です。 |
ArgumentException | 指定したパラメータが、MinValue 未満、または MaxValue よりも大きいと評価されました。 または kind が DateTimeKind 値ではありません。 |

year、month、day の各パラメータに使用できる値は、calendar パラメータによって異なります。calendar を使用して、指定した日付と時刻を表現できない場合にだけ、例外がスローされます。
System.Globalization 名前空間には、GregorianCalendar や JulianCalendar をなどの複数の暦が用意されています。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar)
アセンブリ: 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 _ )
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 calendar As Calendar Dim instance As New DateTime(year, month, day, hour, minute, second, millisecond, calendar)
public DateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar )
public: DateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar^ calendar )
public DateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar )
public function DateTime ( year : int, month : int, day : int, hour : int, minute : int, second : int, millisecond : int, calendar : Calendar )


Kind プロパティは Unspecified に初期化されます。
year、month、および day に使用できる値は calendar によって異なります。calendar を使用して、指定した日付と時刻を表現できない場合にだけ、例外がスローされます。
System.Globalization 名前空間には、GregorianCalendar や JulianCalendar をなどの複数の暦が用意されています。

' 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DateTime コンストラクタ (Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)
アセンブリ: 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 _ )
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 kind As DateTimeKind Dim instance As New DateTime(year, month, day, hour, minute, second, millisecond, kind)
public DateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind )
public: DateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind )
public DateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind )
public function DateTime ( year : int, month : int, day : int, hour : int, minute : int, second : int, millisecond : int, kind : DateTimeKind )


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DateTime コンストラクタ (Int32, Int32, Int32, Calendar)
アセンブリ: 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)


結果として得られた DateTime の時刻は深夜 (00:00:00) です。Kind プロパティは Unspecified に初期化されます。
year、month、および day に使用できる値は calendar によって異なります。calendar を使用して、指定した日付と時刻を表現できない場合にだけ、例外がスローされます。
System.Globalization 名前空間には、GregorianCalendar や JulianCalendar をなどの複数の暦が用意されています。

' 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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)
アセンブリ: 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 _ )
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 kind As DateTimeKind Dim instance As New DateTime(year, month, day, hour, minute, second, kind)
public DateTime ( int year, int month, int day, int hour, int minute, int second, DateTimeKind kind )
public: DateTime ( int year, int month, int day, int hour, int minute, int second, DateTimeKind kind )
public DateTime ( int year, int month, int day, int hour, int minute, int second, DateTimeKind kind )
public function DateTime ( year : int, month : int, day : int, hour : int, minute : int, second : int, kind : DateTimeKind )


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DateTime コンストラクタ (Int64, DateTimeKind)
アセンブリ: mscorlib (mscorlib.dll 内)



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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DateTime フィールド
DateTime プロパティ
DateTime メソッド

名前 | 説明 | |
---|---|---|
![]() | Add | このインスタンスの値に指定した TimeSpan の値を加算します。 |
![]() | AddDays | このインスタンスの値に、指定した日数を加算します。 |
![]() | AddHours | このインスタンスの値に指定した時間数を加算します。 |
![]() | AddMilliseconds | このインスタンスの値に指定したミリ秒数を加算します。 |
![]() | AddMinutes | このインスタンスの値に指定した分数を加算します。 |
![]() | AddMonths | このインスタンスの値に指定した月数を加算します。 |
![]() | AddSeconds | このインスタンスの値に指定した秒数を加算します。 |
![]() | AddTicks | このインスタンスの値に指定したタイマ刻み数を加算します。 |
![]() | AddYears | このインスタンスの値に指定した年数を加算します。 |
![]() | Compare | DateTime の 2 つのインスタンスを比較し、これらの相対値を示す値を返します。 |
![]() | CompareTo | オーバーロードされます。 指定したオブジェクトまたは値型とこのインスタンスとを比較し、これらの相対値を示す値を返します。 |
![]() | DaysInMonth | 指定した月および年の日数を返します。 |
![]() | Equals | オーバーロードされます。 2 つの DateTime オブジェクトが等しいかどうか、または、特定の DateTime インスタンスと別のオブジェクト (DateTime) が等しいかどうかを表す値を返します。 |
![]() | FromBinary | 64 ビットのバイナリ値を逆シリアル化し、元のシリアル化 DateTime オブジェクトを再構築します。 |
![]() | FromFileTime | 指定された Windows ファイル時刻を同等の現地時刻に変換します。 |
![]() | FromFileTimeUtc | 指定された Windows ファイル時刻を同等の UTC 時刻に変換します。 |
![]() | FromOADate | 指定した OLE オートメーション日付と等しい DateTime を返します。 |
![]() | GetDateTimeFormats | オーバーロードされます。 このインスタンスの値を、標準 DateTime 書式指定子によってサポートされるすべての文字列形式に変換します。 |
![]() | GetHashCode | オーバーライドされます。 このインスタンスのハッシュ コードを返します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | GetTypeCode | DateTime 値型の TypeCode を返します。 |
![]() | IsDaylightSavingTime | DateTime のインスタンスが、現在のタイム ゾーンの夏時間の期間内であるどうかを示します。 |
![]() | IsLeapYear | 指定した年が閏年かどうかを示す値を返します。 |
![]() | op_Addition | 指定した日付と時刻に指定した時間間隔を加算して、新しい日付と時刻を作成します。 |
![]() | op_Equality | DateTime の 2 つの指定したインスタンスが等しいかどうかを判断します。 |
![]() | op_GreaterThan | 指定した DateTime が、指定したもう 1 つの DateTime より大きいかどうかを判断します。 |
![]() | op_GreaterThanOrEqual | 指定した DateTime が、指定したもう 1 つの DateTime 以上かどうかを判断します。 |
![]() | op_Inequality | DateTime の 2 つの指定したインスタンスが等しくないかどうかを判断します。 |
![]() | op_LessThan | 指定した DateTime が、指定したもう 1 つの DateTime より小さいかどうかを判断します。 |
![]() | op_LessThanOrEqual | 指定した DateTime が、指定したもう 1 つの DateTime 以下かどうかを判断します。 |
![]() | op_Subtraction | オーバーロードされます。 指定した DateTime から指定した DateTime または TimeSpan を減算します。 |
![]() | Parse | オーバーロードされます。 指定した文字列形式の日付と時刻を等価の DateTime の値に変換します。 |
![]() | ParseExact | オーバーロードされます。 指定した文字列形式の日付と時刻を等価の DateTime の値に変換します。文字列形式の書式は、指定した書式と完全に一致する必要があります。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | SpecifyKind | 指定された DateTime と同じ時刻を表す新しい DateTime オブジェクトを、DateTimeKind 値 (現地時刻、世界協定時刻 (UTC)、または、そのいずれでもないことを示す) に基づいて作成します。 |
![]() | Subtract | オーバーロードされます。 このインスタンスから指定した時刻または存続時間を減算します。 |
![]() | ToBinary | 現在の DateTime オブジェクトを 64 ビットのバイナリ値にシリアル化します。後で、この値を使って、DateTime オブジェクトを再構築できます。 |
![]() | ToFileTime | 現在の DateTime オブジェクトの値を Windows ファイル時刻に変換します。 |
![]() | ToFileTimeUtc | 現在の DateTime オブジェクトの値を Windows ファイル時刻に変換します。 |
![]() | ToLocalTime | 現在の DateTime オブジェクトの値を現地時刻に変換します。 |
![]() | ToLongDateString | このインスタンスの値を、それと等価な長い形式の日付の文字列形式に変換します。 |
![]() | ToLongTimeString | このインスタンスの値を、それと等価の長い時刻書式の文字列形式に変換します。 |
![]() | ToOADate | このインスタンスの値をそれと等価な OLE オートメーション日付に変換します。 |
![]() | ToShortDateString | このインスタンスの値を、それと等価な短い形式の日付の文字列形式に変換します。 |
![]() | ToShortTimeString | このインスタンスの値を、それと等価の短い時刻書式の文字列形式に変換します。 |
![]() | ToString | オーバーロードされます。 オーバーライドされます。 このインスタンスの値を、それと等価の文字列形式に変換します。 |
![]() | ToUniversalTime | 現在の DateTime オブジェクトの値を世界協定時刻 (UTC) に変換します。 |
![]() | TryParse | オーバーロードされます。 指定した文字列形式の日付と時刻を等価の DateTime の値に変換します。 |
![]() | TryParseExact | オーバーロードされます。 指定した文字列形式の日付と時刻を等価の DateTime の値に変換します。文字列形式の書式は、指定した書式と完全に一致する必要があります。 |

名前 | 説明 | |
---|---|---|
![]() | System.IConvertible.ToBoolean | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToByte | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToChar | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToDateTime | 現在の DateTime オブジェクトを返します。 |
![]() | System.IConvertible.ToDecimal | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToDouble | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToInt16 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToInt32 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToInt64 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToSByte | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToSingle | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToType | 現在の DateTime オブジェクトを、指定された型のオブジェクトに変換します。 |
![]() | System.IConvertible.ToUInt16 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToUInt32 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToUInt64 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.Runtime.Serialization.ISerializable.GetObjectData | SerializationInfo オブジェクトに、現在の DateTime オブジェクトをシリアル化するために必要なデータを格納します。 |

DateTime メンバ
DateTime データ型で公開されるメンバを以下の表に示します。




名前 | 説明 | |
---|---|---|
![]() | Add | このインスタンスの値に指定した TimeSpan の値を加算します。 |
![]() | AddDays | このインスタンスの値に、指定した日数を加算します。 |
![]() | AddHours | このインスタンスの値に指定した時間数を加算します。 |
![]() | AddMilliseconds | このインスタンスの値に指定したミリ秒数を加算します。 |
![]() | AddMinutes | このインスタンスの値に指定した分数を加算します。 |
![]() | AddMonths | このインスタンスの値に指定した月数を加算します。 |
![]() | AddSeconds | このインスタンスの値に指定した秒数を加算します。 |
![]() | AddTicks | このインスタンスの値に指定したタイマ刻み数を加算します。 |
![]() | AddYears | このインスタンスの値に指定した年数を加算します。 |
![]() | Compare | DateTime の 2 つのインスタンスを比較し、これらの相対値を示す値を返します。 |
![]() | CompareTo | オーバーロードされます。 指定したオブジェクトまたは値型とこのインスタンスとを比較し、これらの相対値を示す値を返します。 |
![]() | DaysInMonth | 指定した月および年の日数を返します。 |
![]() | Equals | オーバーロードされます。 2 つの DateTime オブジェクトが等しいかどうか、または、特定の DateTime インスタンスと別のオブジェクト (DateTime) が等しいかどうかを表す値を返します。 |
![]() | FromBinary | 64 ビットのバイナリ値を逆シリアル化し、元のシリアル化 DateTime オブジェクトを再構築します。 |
![]() | FromFileTime | 指定された Windows ファイル時刻を同等の現地時刻に変換します。 |
![]() | FromFileTimeUtc | 指定された Windows ファイル時刻を同等の UTC 時刻に変換します。 |
![]() | FromOADate | 指定した OLE オートメーション日付と等しい DateTime を返します。 |
![]() | GetDateTimeFormats | オーバーロードされます。 このインスタンスの値を、標準 DateTime 書式指定子によってサポートされるすべての文字列形式に変換します。 |
![]() | GetHashCode | オーバーライドされます。 このインスタンスのハッシュ コードを返します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | GetTypeCode | DateTime 値型の TypeCode を返します。 |
![]() | IsDaylightSavingTime | DateTime のインスタンスが、現在のタイム ゾーンの夏時間の期間内であるどうかを示します。 |
![]() | IsLeapYear | 指定した年が閏年かどうかを示す値を返します。 |
![]() | op_Addition | 指定した日付と時刻に指定した時間間隔を加算して、新しい日付と時刻を作成します。 |
![]() | op_Equality | DateTime の 2 つの指定したインスタンスが等しいかどうかを判断します。 |
![]() | op_GreaterThan | 指定した DateTime が、指定したもう 1 つの DateTime より大きいかどうかを判断します。 |
![]() | op_GreaterThanOrEqual | 指定した DateTime が、指定したもう 1 つの DateTime 以上かどうかを判断します。 |
![]() | op_Inequality | DateTime の 2 つの指定したインスタンスが等しくないかどうかを判断します。 |
![]() | op_LessThan | 指定した DateTime が、指定したもう 1 つの DateTime より小さいかどうかを判断します。 |
![]() | op_LessThanOrEqual | 指定した DateTime が、指定したもう 1 つの DateTime 以下かどうかを判断します。 |
![]() | op_Subtraction | オーバーロードされます。 指定した DateTime から指定した DateTime または TimeSpan を減算します。 |
![]() | Parse | オーバーロードされます。 指定した文字列形式の日付と時刻を等価の DateTime の値に変換します。 |
![]() | ParseExact | オーバーロードされます。 指定した文字列形式の日付と時刻を等価の DateTime の値に変換します。文字列形式の書式は、指定した書式と完全に一致する必要があります。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | SpecifyKind | 指定された DateTime と同じ時刻を表す新しい DateTime オブジェクトを、DateTimeKind 値 (現地時刻、世界協定時刻 (UTC)、または、そのいずれでもないことを示す) に基づいて作成します。 |
![]() | Subtract | オーバーロードされます。 このインスタンスから指定した時刻または存続時間を減算します。 |
![]() | ToBinary | 現在の DateTime オブジェクトを 64 ビットのバイナリ値にシリアル化します。後で、この値を使って、DateTime オブジェクトを再構築できます。 |
![]() | ToFileTime | 現在の DateTime オブジェクトの値を Windows ファイル時刻に変換します。 |
![]() | ToFileTimeUtc | 現在の DateTime オブジェクトの値を Windows ファイル時刻に変換します。 |
![]() | ToLocalTime | 現在の DateTime オブジェクトの値を現地時刻に変換します。 |
![]() | ToLongDateString | このインスタンスの値を、それと等価な長い形式の日付の文字列形式に変換します。 |
![]() | ToLongTimeString | このインスタンスの値を、それと等価の長い時刻書式の文字列形式に変換します。 |
![]() | ToOADate | このインスタンスの値をそれと等価な OLE オートメーション日付に変換します。 |
![]() | ToShortDateString | このインスタンスの値を、それと等価な短い形式の日付の文字列形式に変換します。 |
![]() | ToShortTimeString | このインスタンスの値を、それと等価の短い時刻書式の文字列形式に変換します。 |
![]() | ToString | オーバーロードされます。 オーバーライドされます。 このインスタンスの値を、それと等価の文字列形式に変換します。 |
![]() | ToUniversalTime | 現在の DateTime オブジェクトの値を世界協定時刻 (UTC) に変換します。 |
![]() | TryParse | オーバーロードされます。 指定した文字列形式の日付と時刻を等価の DateTime の値に変換します。 |
![]() | TryParseExact | オーバーロードされます。 指定した文字列形式の日付と時刻を等価の DateTime の値に変換します。文字列形式の書式は、指定した書式と完全に一致する必要があります。 |

名前 | 説明 | |
---|---|---|
![]() | System.IConvertible.ToBoolean | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToByte | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToChar | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToDateTime | 現在の DateTime オブジェクトを返します。 |
![]() | System.IConvertible.ToDecimal | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToDouble | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToInt16 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToInt32 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToInt64 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToSByte | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToSingle | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToType | 現在の DateTime オブジェクトを、指定された型のオブジェクトに変換します。 |
![]() | System.IConvertible.ToUInt16 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToUInt32 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.IConvertible.ToUInt64 | この変換はサポートされていません。変換を試みると、InvalidCastException がスローされます。 |
![]() | System.Runtime.Serialization.ISerializable.GetObjectData | SerializationInfo オブジェクトに、現在の DateTime オブジェクトをシリアル化するために必要なデータを格納します。 |

DateTime 構造体
アセンブリ: mscorlib (mscorlib.dll 内)

<SerializableAttribute> _ Public Structure DateTime Implements IComparable, IFormattable, IConvertible, ISerializable, _ IComparable(Of DateTime), IEquatable(Of DateTime)
[SerializableAttribute] public struct DateTime : IComparable, IFormattable, IConvertible, ISerializable, IComparable<DateTime>, IEquatable<DateTime>
[SerializableAttribute] public value class DateTime : IComparable, IFormattable, IConvertible, ISerializable, IComparable<DateTime>, IEquatable<DateTime>

DateTime 値型は、A.D. (西暦紀元) 0001 年 1 月 1 日の午前 00:00:00 から A.D. (西暦紀元) 9999 年 12 月 31 日の午後 11:59:59 までの間の値で日付と時刻を表します。
時刻値は 100 ナノ秒単位 (タイマ刻み) で表し、日付は GregorianCalendar 暦の A.D. (西暦紀元) 1 年 1 月 1 日の午前 00:00 からのタイマ刻み数で表します。たとえば、タイマ刻み値 31241376000000000L は、0100 年 1 月 1 日 (金曜日) の深夜 12:00:00 を表します。DateTime 値は、常に、明示的な暦または既定の暦のコンテキストで表されます。
バージョンの考慮事項以前のバージョンの .NET Framework では、DateTime 構造体に、プライベートの Ticks フィールド (62 ビットの符号なしフィールドで日付と時刻を表すタイマ刻み数を格納) と、未使用の 2 ビット フィールドとが連結された、合わせて 64 ビットのフィールドが格納されていました。Ticks フィールドの値は、Ticks プロパティで取得できます。
.NET Framework 2.0 以降では、DateTime 構造体には、Ticks フィールドとプライベートの Kind フィールドとが連結された、合わせて 64 ビットのフィールドが格納されます。Kind フィールドは、DateTime 構造体によって表される時刻が "現地時刻である"、"世界協定時刻 (UTC) である"、または、"そのいずれにも該当しない" のいずれかを示す 2 ビットのフィールドです。Kind フィールドは、主に現地時刻と UTC 時刻との間の変換時に使用され、時刻の比較や算術計算には使用されません。Kind フィールドの値は、Kind プロパティで取得できます。
DateTime 型の時刻値は、多くの場合、世界協定時刻 (UTC) を使用して表されます。世界協定時刻はグリニッジ標準時 (GMT) と呼ばれることもあります。世界協定時刻は、経度 0°を基準として計算された時刻です。UTC は夏時間の影響を受けません。
現地時刻は、特定のタイム ゾーンを基準に計算されます。タイム ゾーンには、特定のオフセット値 (UTC 基準点からの時間のずれ) が割り当てられます。また、現地時刻は、夏時間を加味し、一日の長さを 1 時間遅らせたり、早めたりすることによって調整される場合があります。したがって、現地時刻は、UTC にタイム ゾーン オフセットを加算し、必要に応じて夏時間を調整した時刻になります。UTC 基準点におけるタイム ゾーン オフセットはゼロです。
UTC 時刻は、日時の計算や比較、およびファイルのタイムスタンプを追跡する目的に適しています。これに対し、現地時刻は、ユーザー インターフェイスでの表示に適しています。
時刻が現地時刻であるか、UTC 時刻であるかが不定の場合、DateTime オブジェクトの Kind プロパティは Unspecified になります。現地時刻であるか UTC 時刻であるかが不定の時刻は、DateTime の対応するメンバによって適切に処理されます。
Add や Subtract など、DateTime 構造体を使用した計算では、この構造体の値そのものが変更されるわけではありません。代わりに、計算結果を値として保持する、新しい DateTime 構造体が返されます。
夏時間は、現地時刻と UTC 時刻と間の変換時にのみ考慮され、日時の比較や算術計算時には考慮されません。
DateTime オブジェクトの計算および比較では、対象となる複数のオブジェクトが同じタイム ゾーンの時刻を表している場合にのみ、意味のある結果を得ることができます。そのため、このオブジェクトに対してタイム ゾーンを指定しない場合は、開発者側で、専用の変数を用意したり、特別な方針を設けるなど、なんらかのメカニズムによって、DateTime オブジェクトの作成されたタイム ゾーンを判別できるようにする必要があります。
DateTime の各メンバは、暗黙的にグレゴリオ暦を使用して演算を実行します。ただし、暦を指定するコンストラクタや、System.Globalization.DateTimeFormatInfo などの、IFormatProvider から派生したパラメータで暗黙的に暦を指定するメソッドは例外です。
DateTime 値型と TimeSpan 値型の違う点は、DateTime が瞬間を表し、TimeSpan が時間間隔を表すことです。つまり、たとえば DateTime の 1 つのインスタンスを別のインスタンスから減算すると、それら 2 つのインスタンス間の時間間隔を取得できます。または、現在の DateTime に正の TimeSpan を加算すると将来の日付が算出されます。
DateTime オブジェクトでは、時間間隔を加算したり、減算したりできます。時間間隔の指定には、正数や負数、タイマ刻み数や秒数、または TimeSpan オブジェクトも使用できます。
DateTime 値は、一度、COM アプリケーションに転送し、その後、再びマネージ アプリケーションに戻すことができます。これを "値がラウンドトリップした" と言います。しかし、DateTime 値に時刻しか指定されていないと、期待どおりに値がラウンドトリップしてくれません。
時刻だけ (たとえば、午後 3:00) をラウンドトリップさせた場合、最終的に返る日時は西暦 1899 年 12 月 30 日の午後 3:00 になります。西暦 0001 年 1 月 1 日の午後 3:00 とはなりません。これは、.NET Framework と COM とでは、時刻しか指定しなかった場合に用いられる既定の日付が異なるためです。COM システムでは基準となる日付を西暦 1899 年 12 月 30 日と想定しているのに対し、.NET Framework では西暦 0001 年 1 月 1 日が想定されています。
.NET Framework から COM に時刻しか渡さなかった場合、COM 用の時刻形式に変換するための特殊な処理が実行されます。COM から .NET Framework に時刻だけを渡した場合、特殊な処理は実行されません。特殊な処理を適用すると、1899 年 12 月 30 日以前の日時情報が正しく維持されないためです。逆に言えば、日付を COM からラウンドトリップさせた場合は、.NET Framework と COM 間でその日付が維持されることになります。
.NET Framework と COM における、こうした動作の違いを正しく理解することが大切です。時刻情報だけを指定した DateTime をラウンドトリップさせる場合、最終的に返された DateTime オブジェクトに対し、誤った日付を修正するか無視する処理をアプリケーション側で実装する必要があります。

ほぼ等しい DateTime の値を比較して、一定の小さな範囲の許容誤差において "等しい" と判定する方法を次のコード例に示します。
Class DateTimeTester Shared Function RoughlyEquals(time As DateTime, timeWithWindow As DateTime, windowInSeconds As Integer, frequencyInSeconds As Integer) As Boolean Dim delta As Long = (timeWithWindow.Subtract(time)).TotalSeconds Mod frequencyInSeconds If delta > windowInSeconds Then delta = frequencyInSeconds - delta End If Return Math.Abs(delta) < windowInSeconds End Function 'RoughlyEquals Public Shared Sub Main() Dim window As Integer = 10 Dim freq As Integer = 60 * 60 * 2 ' 2 hours; Dim d1 As DateTime = DateTime.Now Dim d2 As DateTime = d1.AddSeconds((2 * window)) Dim d3 As DateTime = d1.AddSeconds((- 2 * window)) Dim d4 As DateTime = d1.AddSeconds((window / 2)) Dim d5 As DateTime = d1.AddSeconds((- window / 2)) Dim d6 As DateTime = d1.AddHours(2).AddSeconds((2 * window)) Dim d7 As DateTime = d1.AddHours(2).AddSeconds((- 2 * window)) Dim d8 As DateTime = d1.AddHours(2).AddSeconds((window / 2)) Dim d9 As DateTime = d1.AddHours(2).AddSeconds((- window / 2)) Console.WriteLine("d1 ~= d1 [true]: " + CStr(RoughlyEquals(d1, d1, window, freq))) Console.WriteLine("d1 ~= d2 [false]: " + CStr(RoughlyEquals(d1, d2, window, freq))) Console.WriteLine("d1 ~= d3 [false]: " + CStr(RoughlyEquals(d1, d3, window, freq))) Console.WriteLine("d1 ~= d4 [true]: " + CStr(RoughlyEquals(d1, d4, window, freq))) Console.WriteLine("d1 ~= d5 [true]: " + CStr(RoughlyEquals(d1, d5, window, freq))) Console.WriteLine("d1 ~= d6 [false]: " + CStr(RoughlyEquals(d1, d6, window, freq))) Console.WriteLine("d1 ~= d7 [false]: " + CStr(RoughlyEquals(d1, d7, window, freq))) Console.WriteLine("d1 ~= d8 [true]: " + CStr(RoughlyEquals(d1, d8, window, freq))) Console.WriteLine("d1 ~= d9 [true]: " + CStr(RoughlyEquals(d1, d9, window, freq))) End Sub 'Main End Class 'DateTimeTester
class DateTimeTester { static bool RoughlyEquals(DateTime time, DateTime timeWithWindow, int windowInSeconds, int frequencyInSeconds) { long delta = (long)((TimeSpan)(timeWithWindow - time)).TotalSeconds % frequencyInSeconds; delta = delta > windowInSeconds ? frequencyInSeconds - delta : delta; return Math.Abs(delta) < windowInSeconds; } public static void Main() { int window = 10; int freq = 60 * 60 * 2; // 2 hours; DateTime d1 = DateTime.Now; DateTime d2 = d1.AddSeconds(2 * window); DateTime d3 = d1.AddSeconds(-2 * window); DateTime d4 = d1.AddSeconds(window / 2); DateTime d5 = d1.AddSeconds(-window / 2); DateTime d6 = (d1.AddHours(2)).AddSeconds(2 * window); DateTime d7 = (d1.AddHours(2)).AddSeconds(-2 * window); DateTime d8 = (d1.AddHours(2)).AddSeconds(window / 2); DateTime d9 = (d1.AddHours(2)).AddSeconds(-window / 2); Console.WriteLine("d1 ~= d1 [true]: " + RoughlyEquals(d1, d1, window, freq)); Console.WriteLine("d1 ~= d2 [false]: " + RoughlyEquals(d1, d2, window, freq)); Console.WriteLine("d1 ~= d3 [false]: " + RoughlyEquals(d1, d3, window, freq)); Console.WriteLine("d1 ~= d4 [true]: " + RoughlyEquals(d1, d4, window, freq)); Console.WriteLine("d1 ~= d5 [true]: " + RoughlyEquals(d1, d5, window, freq)); Console.WriteLine("d1 ~= d6 [false]: " + RoughlyEquals(d1, d6, window, freq)); Console.WriteLine("d1 ~= d7 [false]: " + RoughlyEquals(d1, d7, window, freq)); Console.WriteLine("d1 ~= d8 [true]: " + RoughlyEquals(d1, d8, window, freq)); Console.WriteLine("d1 ~= d9 [true]: " + RoughlyEquals(d1, d9, window, freq)); } }
bool RoughlyEquals( DateTime time, DateTime timeWithWindow, int windowInSeconds, int frequencyInSeconds ) { long delta = (long)((TimeSpan)(timeWithWindow - time)).TotalSeconds % frequencyInSeconds; delta = delta > windowInSeconds ? frequencyInSeconds - delta : delta; return Math::Abs( delta ) < windowInSeconds; } int main() { int window = 10; int freq = 60 * 60 * 2; // 2 hours; DateTime d1 = DateTime::Now; DateTime d2 = d1.AddSeconds( 2 * window ); DateTime d3 = d1.AddSeconds( -2 * window ); DateTime d4 = d1.AddSeconds( window / 2 ); DateTime d5 = d1.AddSeconds( -window / 2 ); DateTime d6 = (d1.AddHours( 2 )).AddSeconds( 2 * window ); DateTime d7 = (d1.AddHours( 2 )).AddSeconds( -2 * window ); DateTime d8 = (d1.AddHours( 2 )).AddSeconds( window / 2 ); DateTime d9 = (d1.AddHours( 2 )).AddSeconds( -window / 2 ); Console::WriteLine( "d1 ~= d1 [true]: {0}", RoughlyEquals( d1, d1, window, freq ) ); Console::WriteLine( "d1 ~= d2 [false]: {0}", RoughlyEquals( d1, d2, window, freq ) ); Console::WriteLine( "d1 ~= d3 [false]: {0}", RoughlyEquals( d1, d3, window, freq ) ); Console::WriteLine( "d1 ~= d4 [true]: {0}", RoughlyEquals( d1, d4, window, freq ) ); Console::WriteLine( "d1 ~= d5 [true]: {0}", RoughlyEquals( d1, d5, window, freq ) ); Console::WriteLine( "d1 ~= d6 [false]: {0}", RoughlyEquals( d1, d6, window, freq ) ); Console::WriteLine( "d1 ~= d7 [false]: {0}", RoughlyEquals( d1, d7, window, freq ) ); Console::WriteLine( "d1 ~= d8 [true]: {0}", RoughlyEquals( d1, d8, window, freq ) ); Console::WriteLine( "d1 ~= d9 [true]: {0}", RoughlyEquals( d1, d9, window, freq ) ); }
class DateTimeTester { public static boolean RoughlyEquals(DateTime time, DateTime timeWithWindow, int windowInSeconds, int frequencyInSeconds) { long delta = (long)((TimeSpan)timeWithWindow.Subtract(time)). get_TotalSeconds() % frequencyInSeconds; delta = delta > windowInSeconds ? frequencyInSeconds - delta : delta; return (System.Convert.ToBoolean(System.Math.Abs(delta) < windowInSeconds)); } //RoughlyEquals public static void main(String[] args) { int window = 10; int freq = 60 * 60 * 2; // 2 hours; DateTime d1 = DateTime.get_Now(); DateTime d2 = d1.AddSeconds(2 * window); DateTime d3 = d1.AddSeconds(-2 * window); DateTime d4 = d1.AddSeconds(window / 2); DateTime d5 = d1.AddSeconds(-window / 2); DateTime d6 = d1.AddHours(2).AddSeconds(2 * window); DateTime d7 = d1.AddHours(2).AddSeconds(-2 * window); DateTime d8 = d1.AddHours(2).AddSeconds(window / 2); DateTime d9 = d1.AddHours(2).AddSeconds(-window / 2); Console.WriteLine("d1 ~= d1 [true]: " + RoughlyEquals(d1, d1, window, freq)); Console.WriteLine("d1 ~= d2 [false]: " + RoughlyEquals(d1, d2, window, freq)); Console.WriteLine("d1 ~= d3 [false]: " + RoughlyEquals(d1, d3, window, freq)); Console.WriteLine("d1 ~= d4 [true]: " + RoughlyEquals(d1, d4, window, freq)); Console.WriteLine("d1 ~= d5 [true]: " + RoughlyEquals(d1, d5, window, freq)); Console.WriteLine("d1 ~= d6 [false]: " + RoughlyEquals(d1, d6, window, freq)); Console.WriteLine("d1 ~= d7 [false]: " + RoughlyEquals(d1, d7, window, freq)); Console.WriteLine("d1 ~= d8 [true]: " + RoughlyEquals(d1, d8, window, freq)); Console.WriteLine("d1 ~= d9 [true]: " + RoughlyEquals(d1, d9, window, freq)); } //main } //DateTimeTester


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


「Date-Time」に関係したコラム
-
FX(外国為替証拠金取引)のチャート分析ソフトMT4(Meta Trader 4)での時刻表示は、MT4のダウンロード先にもよりますが、一般的には中央ヨーロッパ時間であることが多いようです。日本時間の...
FXのチャート分析ソフトMT4で10分足や2時間足などを表示するには
FX(外国為替証拠金取引)のチャート分析ソフトMT4(Meta Trader 4)では、次の時間足の表示ができます。ティック1分足5分足15分足30分足1時間足4時間足日足週足MT4では、10分足や1...
- Date-Timeのページへのリンク