DateTime.Date プロパティ
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
このインスタンスの日付の部分を取得します。
public:
property DateTime Date { DateTime get(); };
C#
public DateTime Date { get; }
member this.Date : DateTime
Public ReadOnly Property Date As DateTime
このインスタンスと日付が同じで、時刻値が深夜の 12 時 (00:00:00) に設定された新しいオブジェクト。
次の例では、 プロパティを Date 使用して、時刻コンポーネントが 0 (または 0:00:00、または午前 0 時) に設定された値の日付コンポーネント DateTime を抽出します。 また、値を表示 DateTime するときに使用される書式指定文字列に応じて、時刻コンポーネントが書式設定された出力に引き続き表示される可能性があることを示します。
using namespace System;
void main()
{
DateTime^ date1 = gcnew DateTime(2008, 6, 1, 7, 47, 0);
Console::WriteLine(date1->ToString());
// Get date-only portion of date, without its time.
DateTime dateOnly = date1->Date;
// Display date using short date string.
Console::WriteLine(dateOnly.ToString("d"));
// Display date using 24-hour clock.
Console::WriteLine(dateOnly.ToString("g"));
Console::WriteLine(dateOnly.ToString(L"MM/dd/yyyy HH:mm"));
}
// The example displays the following output to the console:
// 6/1/2008 7:47:00 AM
// 6/1/2008
// 6/1/2008 12:00 AM
// 06/01/2008 00:00
C#
using System;
public class Example
{
public static void Main()
{
DateTime date1 = new DateTime(2008, 6, 1, 7, 47, 0);
Console.WriteLine(date1.ToString());
// Get date-only portion of date, without its time.
DateTime dateOnly = date1.Date;
// Display date using short date string.
Console.WriteLine(dateOnly.ToString("d"));
// Display date using 24-hour clock.
Console.WriteLine(dateOnly.ToString("g"));
Console.WriteLine(dateOnly.ToString("MM/dd/yyyy HH:mm"));
}
}
// The example displays output like the following output:
// 6/1/2008 7:47:00 AM
// 6/1/2008
// 6/1/2008 12:00 AM
// 06/01/2008 00:00
open System
let date1 = DateTime(2008, 6, 1, 7, 47, 0)
printfn $"{date1}"
// Get date-only portion of date, without its time.
let dateOnly = date1.Date
// Display date using short date string.
printfn $"{dateOnly:d}"
// Display date using 24-hour clock.
printfn $"{dateOnly:g}"
printfn $"""{dateOnly.ToString "MM/dd/yyyy HH:mm"}"""
// The example displays output like the following output:
// 6/1/2008 7:47:00 AM
// 6/1/2008
// 6/1/2008 12:00 AM
// 06/01/2008 00:00
Module Example
Public Sub Main()
Dim date1 As Date = #6/1/2008 7:47AM#
Console.WriteLine(date1.ToString())
' Get date-only portion of date, without its time.
Dim dateOnly As Date = date1.Date
' Display date using short date string.
Console.WriteLine(dateOnly.ToString("d"))
' Display date using 24-hour clock.
Console.WriteLine(dateOnly.ToString("g"))
Console.WriteLine(dateOnly.ToString("MM/dd/yyyy HH:mm"))
End Sub
End Module
' The example displays output like the following:
' 6/1/2008 7:47:00 AM
' 6/1/2008
' 6/1/2008 12:00 AM
' 06/01/2008 00:00
返されるDateTime値の Kind プロパティの値は、現在のインスタンスの値と同じです。
型は DateTime 1 つの型で日付と時刻の両方を表すので、プロパティによって Date 返される日付を日付と時刻として誤って解釈しないようにすることが重要です。
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。