MS Access VBA 中返回时间的函数是什么? (不是日期和时间)
In MS Access VBA, what is the function for returning the time of day? (Not date AND time)
如何在 Access VBA 中获取当天的时间?我正在尝试构建一个字符串来命名一个包含时间值的文件。我不想要日期时间值,只想要时间值。喜欢 Now() 函数:
CurrentTime = Now()
但我只想要当前时间。
要检索表示时间的字符串值,请使用以下示例:
Dim CurrentTime As String
CurrentTime = Time()
直接从日期时间类型的变量中提取时间值:
Dim ExampleDateTime As DateTime
Dim TimeString As String
ExampleDateTime = Now()
TimeString = Format(ExampleDateTime, "mmm d, yyyy h:nn:ss AMPM")
您当然不应该为日期时间使用字符串变量。始终 - 无一例外 - 使用 Date:
Dim CurrentTime As Date
CurrentTime = Time
然后,为了显示或报告,请根据需要设置格式。
如何在 Access VBA 中获取当天的时间?我正在尝试构建一个字符串来命名一个包含时间值的文件。我不想要日期时间值,只想要时间值。喜欢 Now() 函数:
CurrentTime = Now()
但我只想要当前时间。
要检索表示时间的字符串值,请使用以下示例:
Dim CurrentTime As String
CurrentTime = Time()
直接从日期时间类型的变量中提取时间值:
Dim ExampleDateTime As DateTime
Dim TimeString As String
ExampleDateTime = Now()
TimeString = Format(ExampleDateTime, "mmm d, yyyy h:nn:ss AMPM")
您当然不应该为日期时间使用字符串变量。始终 - 无一例外 - 使用 Date:
Dim CurrentTime As Date
CurrentTime = Time
然后,为了显示或报告,请根据需要设置格式。