DateTimeOffset.Now Property

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)

Public Shared ReadOnly Property Now As DateTimeOffset

Property Value

Type: System.DateTimeOffset
A DateTimeOffset 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).

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.

The following example uses the Now property to retrieve the current date and time and displays it by using each of the standard date and time format strings supported by the DateTimeOffset type.

Module Example
   Public Sub Main()
      Dim fmtStrings() As String = { "d", "D", "f", "F", "g", "G", 
                                     "M", "R", "s", "t", "T", "u",
                                     "y" }

      Dim value As DateTimeOffset = DateTimeOffset.Now
      ' Display date in default format.

      ' Display date using each of the specified formats. 
      For Each fmtString in fmtStrings
         Console.WriteLine("{0} --> {1}", 
                           fmtString, value.ToString(fmtString))
   End Sub 
End Module 
' The example displays output similar to the following: 
'    11/19/2012 10:57:11 AM -08:00 
'    d --> 11/19/2012 
'    D --> Monday, November 19, 2012 
'    f --> Monday, November 19, 2012 10:57 AM 
'    F --> Monday, November 19, 2012 10:57:11 AM 
'    g --> 11/19/2012 10:57 AM 
'    G --> 11/19/2012 10:57:11 AM 
'    M --> November 19 
'    R --> Mon, 19 Nov 2012 18:57:11 GMT 
'    s --> 2012-11-19T10:57:11 
'    t --> 10:57 AM 
'    T --> 10:57:11 AM 
'    u --> 2012-11-19 18:57:11Z 
'    y --> November, 2012

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 
   dto = DateTimeOffset.Now
   If dto.Millisecond <> ms Then
      ms = dto.Millisecond
      Console.WriteLine("{0}:{1:d3} ms. {2}", _
                        dto.ToString("M/d/yyyy h:mm:ss"), _
                        ms, dto.ToString("zzz"))
      ctr += 1
   End If 
Loop While ctr < 100

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1, 3.0 SP1, 2.0 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft