DateTime.Now DateTime.Now DateTime.Now DateTime.Now Property

Definition

コンピューター上の現在の日時を現地時刻で表した 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

Property Value

現在の現地日時を値として保持するオブジェクト。 An object whose value is the current local date and time.

Examples

次の例では、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

Remarks

Nowプロパティが返す、DateTime現在の日付とローカル コンピューターの時刻を表す値です。The Now property returns a DateTime value that represents the current date and time on the local computer. 間に相違があることに注意してください、DateTimeを 0001 年 1 月 1 日午前 0 時から経過したタイマー刻みの数を表す値の文字列表現と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 version 2.0 では、戻り値は、DateTimeKindプロパティが返すDateTimeKind.Localします。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.

Applies to

See Also