DateTimeOffset.Now Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets a DateTimeOffset object that is set to the current date and time on the current computer, with the offset set to the local time's offset from Coordinated Universal Time (UTC).

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared ReadOnly Property Now As DateTimeOffset
public static DateTimeOffset Now { get; }

Property Value

Type: System.DateTimeOffset
An object whose date and time is the current local time and whose offset is the local time zone's offset from Coordinated Universal Time (UTC).

Remarks

The precision of the current local time's millisecond component depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.

Examples

The following example uses the Now and Millisecond properties to determine the resolution of the system clock. It displays the time only when the value of its millisecond component has changed.

Dim dto As DateTimeOffset
Dim ctr As Integer
Dim ms As Integer
Do
   dto = DateTimeOffset.Now
   If dto.Millisecond <> ms Then
      ms = dto.Millisecond
      outputBlock.Text &= String.Format("{0}:{1:d3} ms. {2}", _
                        dto.ToString("M/d/yyyy h:mm:ss"), _
                        ms, dto.ToString("zzz")) & vbCrLf
      ctr += 1
   End If
Loop While ctr < 100
DateTimeOffset dto;
int ctr = 0;
int ms = 0;
do
{
   dto = DateTimeOffset.Now;
   if (dto.Millisecond != ms)
   {
      ms = dto.Millisecond;
      outputBlock.Text += String.Format("{0}:{1:d3} ms. {2}",
                        dto.ToString("M/d/yyyy h:mm:ss"),
                        ms, dto.ToString("zzz")) + "\n";
      ctr++;
   }
} while (ctr < 100);

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.