다음을 통해 공유


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 보여 줍니다. 메서드에 대한 세 번째 호출에서 ToString(String) 생성된 출력은 g 형식 지정자를 사용하여 시간 구성 요소(0)를 포함합니다.

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 현재 날짜와 현재 시간을 모두 반환합니다.

적용 대상

추가 정보