Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

DateAndTime.Timer Property

Returns a Double value representing the number of seconds elapsed since midnight.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
'Declaration
Public Shared ReadOnly Property Timer As Double

Property Value

Type: System.Double
Returns a Double value representing the number of seconds elapsed since midnight.

The Timer property returns both the seconds and the milliseconds since the most recent midnight. The seconds are in the integral part of the return value, and the milliseconds are in the fractional part.

This example uses the Timer property to pause the application. It can perform other processing during the pause.

Public Sub waitFiveSeconds()
    If TimeOfDay >= #11:59:55 PM# Then
        MsgBox("The current time is within 5 seconds of midnight" & 
            vbCrLf & "The timer returns to 0.0 at midnight")
        Return 
    End If 
    Dim start, finish, totalTime As Double 
    If (MsgBox("Press Yes to pause for 5 seconds", MsgBoxStyle.YesNo)) =
         MsgBoxResult.Yes Then

        start = Microsoft.VisualBasic.DateAndTime.Timer
        ' Set end time for 5-second duration.
        finish = start + 5.0
        Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
        ' Do other processing while waiting for 5 seconds to elapse. 
        Loop
        totalTime = Microsoft.VisualBasic.DateAndTime.Timer - start
        MsgBox("Paused for " & totalTime & " seconds")
    End If 
End Sub

Note that you must qualify the Timer property with the Microsoft.VisualBasic namespace, because Timer is also a defined class in the System.Threading, System.Timers, and System.Windows.Forms namespaces.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.