TimeValue 函数TimeValue function

返回包含时间的 Variant (Date)。Returns a Variant (Date) containing the time.

语法Syntax

TimeValue(time)TimeValue(time)

必需的_time_ 参数通常是一个字符串表达式, 表示从 0:00:00 (12:00:00 A.M.) 到 23:59:59 (11:59:59 P.M.) 的时间 (包括这两个时间)。The required time argument is normally a string expression representing a time from 0:00:00 (12:00:00 A.M.) to 23:59:59 (11:59:59 P.M.), inclusive. 但是,time 也可以是表示该范围内时间的任意表达式However, time can also be any expression that represents a time in that range. 如果 time 包含 Null,则返回 NullIf time contains Null, Null is returned.

备注Remarks

可以使用12小时制或24小时制输入有效的时间。You can enter valid times by using a 12-hour or 24-hour clock. 例如, "2:24PM""14:24"都是有效的_时间_参数。For example, "2:24PM" and "14:24" are both valid time arguments.

如果 time 参数包含日期信息,则 TimeValue 不返回该信息。If the time argument contains date information, TimeValue doesn't return it. 但是,如果 time 包括无效日期信息,则会出现错误。However, if time includes invalid date information, an error occurs.

示例Example

此示例使用 TimeValue 函数将字符串转换为时间。This example uses the TimeValue function to convert a string to a time. 还可以使用日期字符串直接向 VariantDate 变量分配时间,例如,MyTime = #4:35:17 PM#。You can also use date literals to directly assign a time to a Variant or Date variable, for example, MyTime = #4:35:17 PM#.

Dim MyTime
MyTime = TimeValue("4:35:17 PM")    ' Return a time.

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.