DateTime.Today プロパティ

定義

現在の日付を取得します。

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 書式指定文字列の一部を使用して値を書式設定する方法についても説明します。 メソッドの 3 番目の呼び出し ToString(String) によって生成される出力では、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 以降では、戻り値はDateTime、 プロパティが Kind を返す Localです。

現在の時刻を指定せずに現在の日付を返すの Today で、 プロパティは日付のみを操作するアプリケーションでの使用に適しています。 詳細については、「 DateTime、DateTimeOffset、TimeSpan、TimeZoneInfo の選択」を参照してください。 これに対し、 プロパティは TimeOfDay 現在の日付を含まない現在の時刻を返し Now 、 プロパティは現在の日付と現在の時刻の両方を返します。

適用対象

こちらもご覧ください