DateTime.Today プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在の日付を取得します。
public:
static property DateTime Today { DateTime get(); };
public static DateTime Today { get; }
static member Today : DateTime
Public Shared ReadOnly Property Today As DateTime
プロパティ値
時刻コンポーネントが 00:00:00 に設定された、今日の日付に設定されているオブジェクト。
例
次の例では、 Date プロパティを使用して現在の日付を取得します。 また、標準の日時書式指定文字列の一部を使用して DateTime 値を書式設定する方法についても説明します。 ToString(String) メソッドの 3 番目の呼び出しによって生成される出力では、g 書式指定子を使用して時刻コンポーネント (ゼロ) が含まれる点に注意してください。
using System;
public class Example
{
public static void Main()
{
// Get the current date.
DateTime thisDay = DateTime.Today;
// Display the date in the default (general) format.
Console.WriteLine(thisDay.ToString());
Console.WriteLine();
// Display the date in a variety of formats.
Console.WriteLine(thisDay.ToString("d"));
Console.WriteLine(thisDay.ToString("D"));
Console.WriteLine(thisDay.ToString("g"));
}
}
// The example displays output similar to the following:
// 5/3/2012 12:00:00 AM
//
// 5/3/2012
// Thursday, May 03, 2012
// 5/3/2012 12:00 AM
open System
// Get the current date.
let thisDay = DateTime.Today
// Display the date in the default (general) format.
printfn $"{thisDay}\n"
// Display the date in a variety of formats.
printfn $"{thisDay:d}"
printfn $"{thisDay:D}"
printfn $"{thisDay:g}"
// The example displays output similar to the following:
// 5/3/2012 12:00:00 AM
//
// 5/3/2012
// Thursday, May 03, 2012
// 5/3/2012 12:00 AM
Module modMain
Public Sub Main()
' Get the current date.
Dim thisDay As DateTime = DateTime.Today
' Display the date in the default (general) format.
Console.WriteLine(thisDay.ToString())
Console.WriteLine()
' Display the date in a variety of formats.
Console.WriteLine(thisDay.ToString("d"))
Console.WriteLine(thisDay.ToString("D"))
Console.WriteLine(thisDay.ToString("g"))
End Sub
End Module
' The example displays output similar to the following:
' 5/3/2012 12:00:00 AM
'
' 5/3/2012
' Thursday, May 03, 2012
' 5/3/2012 12:00 AM
注釈
.NET Framework バージョン 2.0 以降では、戻り値は、Kind プロパティがLocalを返すDateTimeです。
現在の時刻なしで現在の日付が返されるため、 Today プロパティは、日付のみを操作するアプリケーションでの使用に適しています。 詳細については、「 DateTime、DateTimeOffset、TimeSpan、TimeZoneInfo の選択」を参照してください。 これに対し、 TimeOfDay プロパティは現在の日付を含まない現在の時刻を返し、 Now プロパティは現在の日付と現在の時刻の両方を返します。