DateTime.Now Eigenschaft

Definition

Ruft ein DateTime-Objekt ab, das auf das aktuelle Datum und die aktuelle Zeit auf dem lokalen Rechner als Ortszeit festgelegt ist.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

Eigenschaftswert

Ein Objekt, dessen Wert die aktuelle lokale Datums- und Uhrzeitangabe ist.An object whose value is the current local date and time.

Beispiele

Im folgenden Beispiel werden die Eigenschaften "Now" und "UtcNow" verwendet, um das aktuelle lokale Datum und die aktuelle Uhrzeit sowie das aktuelle universelle koordinierte Datum und die Uhrzeit abzurufen.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. Anschließend werden die Zeichen folgen mithilfe der Formatierungs Konventionen einer Reihe von Kulturen zusammen mit den Werten der Eigenschaften des Kind angezeigt.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

Hinweise

Die Now-Eigenschaft gibt einen DateTime-Wert zurück, der das aktuelle Datum und die aktuelle Uhrzeit auf dem lokalen Computer darstellt.The Now property returns a DateTime value that represents the current date and time on the local computer. Beachten Sie, dass es einen Unterschied zwischen einem DateTime-Wert gibt, der die Anzahl der Ticks darstellt, die seit Mitternacht des 1. Januar 0001 verstrichen sind, sowie die Zeichen folgen Darstellung dieses DateTime-Werts, der einen Datums-und Uhrzeitwert in einem kulturspezifisches bestimmtes Format.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. Weitere Informationen zum Formatieren von Datums-und Uhrzeitwerten finden Sie in der ToString-Methode.For information on formatting date and time values, see the ToString method. Im folgenden Beispiel wird die kurze Datums-und Uhrzeit Zeichenfolge in einer Reihe von kulturspezifischen Formaten angezeigt.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

Die Auflösung dieser Eigenschaft hängt vom System Timer ab, der vom zugrunde liegenden Betriebssystem abhängt.The resolution of this property depends on the system timer, which depends on the underlying operating system. Der Wert liegt tendenziell zwischen 0,5 und 15 Millisekunden.It tends to be between 0.5 and 15 milliseconds. Daher kann es vorkommen, dass wiederholte Aufrufe der Now-Eigenschaft in einem kurzen Zeitintervall (z. b. in einer-Schleife) denselben Wert zurückgeben.As a result, repeated calls to the Now property in a short time interval, such as in a loop, may return the same value.

Die Eigenschaft "Now" wird häufig verwendet, um die Leistung zu messen.The Now property is frequently used to measure performance. Aufgrund der geringen Auflösung ist Sie jedoch nicht für die Verwendung als Benchmarktool geeignet.However, because of its low resolution, it is not suitable for use as a benchmarking tool. Eine bessere Alternative ist die Verwendung der Stopwatch-Klasse.A better alternative is to use the Stopwatch class.

Beginnend mit der .NET Framework Version 2,0 ist der Rückgabewert ein DateTime, dessen Kind-Eigenschaft DateTimeKind.Local zurückgibt.Starting with the .NET Framework version 2.0, the return value is a DateTime whose Kind property returns DateTimeKind.Local.

Hinweis

Sie können auch die DateTimeOffset.Now-Eigenschaft verwenden, um das aktuelle lokale Datum und die aktuelle Uhrzeit abzurufen.You can also use the DateTimeOffset.Now property to retrieve the current local date and time. Dadurch kann eine lokale Zeit eindeutig als einzelner Zeitpunkt ausgedrückt werden, was wiederum dazu führt, dass der Zeitwert Computer übergreifend portabel ist.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.

Gilt für:

Siehe auch