DateAndTime.Timer 屬性

定義

回傳 Double 自午夜以來經過的秒數。

public:
 static property double Timer { double get(); };
public static double Timer { get; }
static member Timer : double
Public ReadOnly Property Timer As Double

屬性值

這個數值代表自午夜以來經過的秒數。

範例

此範例使用 該 Timer 屬性來暫停應用程式。 它在暫停期間還能執行其他處理。

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

請注意,您必須以 Microsoft.VisualBasic 命名空間來限定 Timer 屬性,因為 Timer 同時也是 System.ThreadingSystem.TimersSystem.Windows.Forms 命名空間中的定義類別。

備註

Timer 屬性會回傳自最近午夜以來的秒數與毫秒。 秒數屬於回傳值的整數部分,毫秒則屬於分數部分。

適用於

另請參閱