DateTime.Date 속성

정의

이 인스턴스의 날짜 구성 요소를 가져옵니다.

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

속성 값

DateTime

이 인스턴스와 동일한 날짜를 갖고 시간 값이 12:00:00 자정(00:00:00)으로 설정된 새 개체입니다.

예제

다음 예제에서는 이 속성을 사용하여 Date 시간 구성 요소가 0(또는 0:00:00 또는 자정)으로 설정된 값의 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
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 단일 형식의 날짜와 시간을 모두 나타내므로 속성에서 반환 Date 된 날짜를 날짜 및 시간으로 잘못 해석하지 않는 것이 중요합니다.

적용 대상