DateTime.Now 속성

정의

이 컴퓨터의 현재 날짜와 시간으로 설정되고 현지 시간으로 표시되는 DateTime 개체를 가져옵니다.

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

속성 값

DateTime

현재 현지 날짜와 시간이 값인 개체입니다.

예제

다음 예제에서는 현재 로컬 날짜 및 시간 및 UtcNow 현재 UTC (범용 조정) 날짜 및 시간을 검색 하는 속성을 사용 합니다Now. 그런 다음 여러 문화권의 서식 규칙을 사용하여 해당 속성 값 Kind 과 함께 문자열을 표시합니다.

using namespace System;
using namespace System::Globalization;

void main()
{
   DateTime localDate = DateTime::Now;
   DateTime utcDate = DateTime::UtcNow;
   array<String^>^ cultureNames = { "en-US", "en-GB", "fr-FR",
                                    "de-DE", "ru-RU" } ;

   for each (String^ cultureName in cultureNames) {
      CultureInfo^ culture = gcnew CultureInfo(cultureName);
      Console::WriteLine("{0}:", culture->NativeName);
      Console::WriteLine("   Local date and time: {0}, {1:G}",
                         localDate.ToString(culture), localDate.Kind);
      Console::WriteLine("   UTC date and time: {0}, {1:G}\n",
                         utcDate.ToString(culture), utcDate.Kind);
   }
}
// The example displays the following output:
//       English (United States):
//          Local date and time: 6/19/2015 10:35:50 AM, Local
//          UTC date and time: 6/19/2015 5:35:50 PM, Utc
//
//       English (United Kingdom):
//          Local date and time: 19/06/2015 10:35:50, Local
//          UTC date and time: 19/06/2015 17:35:50, Utc
//
//       français (France):
//          Local date and time: 19/06/2015 10:35:50, Local
//          UTC date and time: 19/06/2015 17:35:50, Utc
//
//       Deutsch (Deutschland):
//          Local date and time: 19.06.2015 10:35:50, Local
//          UTC date and time: 19.06.2015 17:35:50, Utc
//
//       русский (Россия):
//          Local date and time: 19.06.2015 10:35:50, Local
//          UTC date and time: 19.06.2015 17:35:50, Utc
using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      DateTime localDate = DateTime.Now;
      DateTime utcDate = DateTime.UtcNow;
      String[] cultureNames = { "en-US", "en-GB", "fr-FR",
                                "de-DE", "ru-RU" } ;

      foreach (var cultureName in cultureNames) {
         var culture = new CultureInfo(cultureName);
         Console.WriteLine("{0}:", culture.NativeName);
         Console.WriteLine("   Local date and time: {0}, {1:G}",
                           localDate.ToString(culture), localDate.Kind);
         Console.WriteLine("   UTC date and time: {0}, {1:G}\n",
                           utcDate.ToString(culture), utcDate.Kind);
      }
   }
}
// The example displays the following output:
//       English (United States):
//          Local date and time: 6/19/2015 10:35:50 AM, Local
//          UTC date and time: 6/19/2015 5:35:50 PM, Utc
//
//       English (United Kingdom):
//          Local date and time: 19/06/2015 10:35:50, Local
//          UTC date and time: 19/06/2015 17:35:50, Utc
//
//       français (France):
//          Local date and time: 19/06/2015 10:35:50, Local
//          UTC date and time: 19/06/2015 17:35:50, Utc
//
//       Deutsch (Deutschland):
//          Local date and time: 19.06.2015 10:35:50, Local
//          UTC date and time: 19.06.2015 17:35:50, Utc
//
//       русский (Россия):
//          Local date and time: 19.06.2015 10:35:50, Local
//          UTC date and time: 19.06.2015 17:35:50, Utc
open System
open System.Globalization

let localDate = DateTime.Now
let utcDate = DateTime.UtcNow
let cultureNames = 
    [ "en-US"; "en-GB"; "fr-FR"; "de-DE"; "ru-RU" ] 

for cultureName in cultureNames do
    let culture = CultureInfo cultureName
    printfn $"{culture.NativeName}:"
    printfn $"   Local date and time: {localDate.ToString culture}, {localDate.Kind:G}"
    printfn $"   UTC date and time: {utcDate.ToString culture}, {utcDate.Kind:G}\n"

// The example displays the following output:
//       English (United States):
//          Local date and time: 6/19/2015 10:35:50 AM, Local
//          UTC date and time: 6/19/2015 5:35:50 PM, Utc
//
//       English (United Kingdom):
//          Local date and time: 19/06/2015 10:35:50, Local
//          UTC date and time: 19/06/2015 17:35:50, Utc
//
//       français (France):
//          Local date and time: 19/06/2015 10:35:50, Local
//          UTC date and time: 19/06/2015 17:35:50, Utc
//
//       Deutsch (Deutschland):
//          Local date and time: 19.06.2015 10:35:50, Local
//          UTC date and time: 19.06.2015 17:35:50, Utc
//
//       русский (Россия):
//          Local date and time: 19.06.2015 10:35:50, Local
//          UTC date and time: 19.06.2015 17:35:50, Utc
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim localDate = DateTime.Now
      Dim utcDate = DateTime.UtcNow
      Dim cultureNames() As String = { "en-US", "en-GB", "fr-FR",
                                       "de-DE", "ru-RU" }

      For Each cultureName In cultureNames
         Dim culture As New CultureInfo(cultureName)
         Console.WriteLine("{0}:", culture.NativeName)
         Console.WriteLine("   Local date and time: {0}, {1:G}",
                           localDate.ToString(culture), localDate.Kind)
         Console.WriteLine("   UTC date and time: {0}, {1:G}",
                           utcDate.ToString(culture), utcDate.Kind)
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'       English (United States):
'          Local date and time: 6/19/2015 10:35:50 AM, Local
'          UTC date and time: 6/19/2015 5:35:50 PM, Utc
'
'       English (United Kingdom):
'          Local date and time: 19/06/2015 10:35:50, Local
'          UTC date and time: 19/06/2015 17:35:50, Utc
'
'       français (France):
'          Local date and time: 19/06/2015 10:35:50, Local
'          UTC date and time: 19/06/2015 17:35:50, Utc
'
'       Deutsch (Deutschland):
'          Local date and time: 19.06.2015 10:35:50, Local
'          UTC date and time: 19.06.2015 17:35:50, Utc
'
'       русский (Россия):
'          Local date and time: 19.06.2015 10:35:50, Local
'          UTC date and time: 19.06.2015 17:35:50, Utc

설명

이 속성은 Now 로컬 컴퓨터의 현재 날짜 및 시간을 나타내는 값을 반환 DateTime 합니다. 0001년 1월 1일 자정 이후 경과된 틱 수를 나타내는 값과 문화권별 형식으로 날짜 및 시간 값을 나타내는 해당 DateTime 값의 문자열 표현 사이에 DateTime 는 차이가 있습니다. 날짜 및 시간 값의 서식 지정에 대한 자세한 내용은 메서드를 참조하세요 ToString . 다음 예제에서는 짧은 날짜 및 시간 문자열을 다양한 문화권별 형식으로 표시합니다.

using namespace System;
using namespace System::Globalization;

void main()
{
   DateTime localDate = DateTime::Now;
   array<String^>^ cultureNames = { "en-US", "en-GB", "fr-FR",
                                    "de-DE", "ru-RU" };

   for each (String^ cultureName in cultureNames) {
      CultureInfo^ culture = gcnew CultureInfo(cultureName);
      Console::WriteLine("{0}: {1}", cultureName,
                         localDate.ToString(culture));
   }
}
// The example displays the following output:
//       en-US: 6/19/2015 10:03:06 AM
//       en-GB: 19/06/2015 10:03:06
//       fr-FR: 19/06/2015 10:03:06
//       de-DE: 19.06.2015 10:03:06
//       ru-RU: 19.06.2015 10:03:06
using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      DateTime localDate = DateTime.Now;
      String[] cultureNames = { "en-US", "en-GB", "fr-FR",
                                "de-DE", "ru-RU" };

      foreach (var cultureName in cultureNames) {
         var culture = new CultureInfo(cultureName);
         Console.WriteLine("{0}: {1}", cultureName,
                           localDate.ToString(culture));
      }
   }
}
// The example displays the following output:
//       en-US: 6/19/2015 10:03:06 AM
//       en-GB: 19/06/2015 10:03:06
//       fr-FR: 19/06/2015 10:03:06
//       de-DE: 19.06.2015 10:03:06
//       ru-RU: 19.06.2015 10:03:06
open System
open System.Globalization

let localDate = DateTime.Now
let cultureNames = 
    [ "en-US"; "en-GB"; "fr-FR"; "de-DE"; "ru-RU" ]

for cultureName in cultureNames do
    let culture = CultureInfo cultureName
    printfn $"{cultureName}: {localDate.ToString culture}"

// The example displays the following output:
//       en-US: 6/19/2015 10:03:06 AM
//       en-GB: 19/06/2015 10:03:06
//       fr-FR: 19/06/2015 10:03:06
//       de-DE: 19.06.2015 10:03:06
//       ru-RU: 19.06.2015 10:03:06
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim localDate = DateTime.Now
      Dim cultureNames() As String = { "en-US", "en-GB", "fr-FR",
                                       "de-DE", "ru-RU" }

      For Each cultureName In cultureNames
         Dim culture As New CultureInfo(cultureName)
         Console.WriteLine("{0}: {1}", cultureName,
                           localDate.ToString(culture))
      Next
   End Sub
End Module
' The example displays the following output:
'    en-US: 6/19/2015 10:03:06 AM
'    en-GB: 19/06/2015 10:03:06
'    fr-FR: 19/06/2015 10:03:06
'    de-DE: 19.06.2015 10:03:06
'    ru-RU: 19.06.2015 10:03:06

이 속성의 확인은 기본 운영 체제에 따라 달라지는 시스템 타이머에 따라 다릅니다. 0.5~15밀리초 사이인 경향이 있습니다. 따라서 루프와 같이 짧은 시간 간격으로 속성에 대한 반복 호출 Now 이 동일한 값을 반환할 수 있습니다.

Now 속성은 성능을 측정하는 데 자주 사용됩니다. 그러나 해상도가 낮기 때문에 벤치마킹 도구로 사용하기에는 적합하지 않습니다. 더 나은 대안은 클래스를 사용하는 것입니다 Stopwatch .

.NET Framework 버전 2.0부터 반환 값은 해당 속성이 DateTime Kind 반환되는 DateTimeKind.Local값입니다.

참고

이 속성을 사용하여 DateTimeOffset.Now 현재 로컬 날짜 및 시간을 검색할 수도 있습니다. 이를 통해 로컬 시간을 단일 시점으로 명확하게 표현할 수 있으므로 컴퓨터에서 해당 시간 값을 이식할 수 있습니다.

적용 대상

추가 정보