DateTime.Now 속성

정의

이 컴퓨터의 현재 날짜와 시간으로 설정되고 현지 시간으로 표시되는 DateTime 개체를 가져옵니다.Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.

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

속성 값

현재 현지 날짜와 시간이 값인 개체입니다.An object whose value is the current local date and time.

예제

다음 예제에서는 NowUtcNow 속성을 사용 하 여 현재 현지 날짜와 시간을 검색 하 고 UTC (협정 세계시) 날짜와 시간을 검색 합니다.The following example uses the Now and UtcNow properties to retrieve the current local date and time and the current universal coordinated (UTC) date and time. 그런 다음 해당 Kind 속성의 값과 함께 문자열을 표시 하기 위해 여러 문화권의 서식 지정 규칙을 사용 합니다.It then uses the formatting conventions of a number of cultures to display the strings, along with the values of the their Kind properties.

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
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 값을 반환 합니다.The Now property returns a DateTime value that represents the current date and time on the local computer. DateTime 값은 0001 년 1 월 1 일 자정 이후 경과 된 틱 수를 나타내고 해당 DateTime 값의 문자열 표현에 차이가 있으므로 문화권별 형식으로 날짜 및 시간 값을 표시 합니다.Note that there is a difference between a DateTime value, which represents the number of ticks that have elapsed since midnight of January 1, 0001, and the string representation of that DateTime value, which expresses a date and time value in a culture-specific-specific format. 날짜 및 시간 값의 서식을 지정 하는 방법에 대 한 자세한 내용은 ToString 메서드를 참조 하세요.For information on formatting date and time values, see the ToString method. 다음 예제에서는 여러 가지 문화권별 형식에서에서의 간단한 날짜 및 시간 문자열을 표시합니다.The following example displays the short date and time string in a number of culture-specific formats.

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
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

이 속성의 해결 방법을 기본 운영 체제에 따라 시스템 타이머에 따라 달라 집니다.The resolution of this property depends on the system timer, which depends on the underlying operating system. 이 0.5 15 밀리초 사이 여야 하는 경향이 있습니다.It tends to be between 0.5 and 15 milliseconds. 따라서 루프에서와 같이 짧은 시간 간격으로 Now 속성을 반복 해 서 호출 하면 동일한 값을 반환할 수 있습니다.As a result, repeated calls to the Now property in a short time interval, such as in a loop, may return the same value.

Now 속성은 성능을 측정 하는 데 자주 사용 됩니다.The Now property is frequently used to measure performance. 그러나 낮은 해상도 인해 적합 하지 벤치마킹 도구를 사용 합니다.However, because of its low resolution, it is not suitable for use as a benchmarking tool. 더 나은 방법은 Stopwatch 클래스를 사용 하는 것입니다.A better alternative is to use the Stopwatch class.

.NET Framework 버전 2.0부터 반환 값은 Kind 속성이 DateTimeKind.Local를 반환 하는 DateTime입니다.Starting with the .NET Framework version 2.0, the return value is a DateTime whose Kind property returns DateTimeKind.Local.

참고

DateTimeOffset.Now 속성을 사용 하 여 현재 현지 날짜와 시간을 검색할 수도 있습니다.You can also use the DateTimeOffset.Now property to retrieve the current local date and time. 현지 시간 따라서 시간 값을 휴대용 컴퓨터 시간 내에 단일 시점으로 명확 하 게 표현 될 수 있습니다.It allows a local time to be expressed unambiguously as a single point in time, which in turn makes that time value portable across computers.

적용 대상

추가 정보