Timer 函数

应用对象
Microsoft 365 专属 Access Access 2024 Access 2021 Access 2019 Access 2016

返回一个 Single 值,表示自午夜后经过的秒数。

语法

Timer

备注

在 Microsoft Windows 中, 计时器 函数返回秒的小数部分。 在 Macintosh 上,计时器分辨率为 1 秒。

查询示例

Expression 结果
SELECT 计时器 () AS SecondsPast FROM ProductSales GROUP BY Timer () ; 根据系统时间返回自午夜以来经过的秒数,并显示在 SecondsPast 列中。

VBA 示例

注意

下面的示例演示了如何在 Visual Basic for Applications (VBA) 模块中使用此函数。 有关使用 VBA 的详细信息,请在搜索旁边的下拉列表中选择“开发人员参考”,并在搜索框中输入一个或多个术语。

此示例使用 Timer 函数暂停应用程序。 该示例还使用 DoEvents 在暂停期间向其他进程屈服。

Dim PauseTime, Start, Finish, TotalTime
If (MsgBox("Press Yes to pause for 5 seconds", _
        4)) = vbYes Then
    PauseTime = 5    ' Set duration.
    Start = Timer    ' Set start time.
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
    Loop
    Finish = Timer    ' Set end time.
    TotalTime = Finish - Start  ' Calculate total time.
    MsgBox "Paused for " & TotalTime & " seconds"
Else
    End
End If

选择正确的日期函数