DateTime.Today 속성

정의

현재 날짜를 가져옵니다.

public:
 static property DateTime Today { DateTime get(); };
public static DateTime Today { get; }
member this.Today : DateTime
Public Shared ReadOnly Property Today As DateTime

속성 값

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부터 반환 값은 해당 속성이 DateTime Kind 반환되는 Local값입니다.

현재 시간을 제외한 현재 날짜를 반환 하기 때문에 Today 속성이 날짜에만 사용 하는 애플리케이션에 적합 합니다. 자세한 내용은 DateTime, DateTimeOffset, TimeSpan 및 TimeZoneInfo 중에서 선택을 참조하세요. 반면에 이 속성은 TimeOfDay 현재 날짜가 없는 현재 시간을 반환하고 속성은 Now 현재 날짜와 현재 시간을 모두 반환합니다.

적용 대상

추가 정보