Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
Assembly: mscorlib (in mscorlib.dll)
The DateTime value that represents the current date and time on the local computer. 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. For information on formatting date and time values, see the ToStringmethod. The following example displays the short date and time string in a number of culture-specific formats.property returns a
The resolution of this property depends on the system timer, which is approximately 15 milliseconds on Windows systems.As a result, repeated calls to theproperty in a short time interval, such as in a loop, may return the same value.
The Stopwatch class.property is frequently used to measure performance. However, because of its low resolution, it is not suitable for use as a benchmarking tool. A better alternative is to use the
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.
The following example uses the UtcNow properties to retrieve the current local date and time and the current universal coordinated (UTC) date and time. It then uses the formatting conventions of a number of cultures to display the strings, along with the values of the their Kind properties.and
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1