TimeSerial 函数TimeSerial function

返回包含特定的小时、分钟和秒所对应的时间的 Variant (Date)。Returns a Variant (Date) containing the time for a specific hour, minute, and second.


TimeSerial(小时分钟)TimeSerial(hour, minute, second)

TimeSerial 函数语法具有以下命名参数The TimeSerial function syntax has these named arguments:

PartPart 说明Description
七点hour 必需;Variant (Integer)。Required; Variant (Integer). 介于 0 (12:00 A.M.) 和 23 (11:00 P.M.) 之间的数字(含这两个数字)或数值表达式Number between 0 (12:00 A.M.) and 23 (11:00 P.M.), inclusive, or a numeric expression.
还要minute 必需;Variant (Integer)。Required; Variant (Integer). 任何数值表达式。Any numeric expression.
第二个second 必需;Variant (Integer)。Required; Variant (Integer). 任何数值表达式。Any numeric expression.


若要指定时间 (如 11:59:59), 每个TimeSerial参数的数字范围应在该单位的正常区域中。也就是说, 0–23 表示小时, 0–59 表示分钟和秒。To specify a time, such as 11:59:59, the range of numbers for each TimeSerial argument should be in the normal range for the unit; that is, 0–23 for hours and 0–59 for minutes and seconds. 但是, 也可以使用任何表示特定时间之前或之后的小时数、分钟数或秒数的数值表达式, 指定每个参数的相对时间。However, you can also specify relative times for each argument by using any numeric expression that represents some number of hours, minutes, or seconds before or after a certain time.

下面的示例使用表达式而不是绝对时间数。The following example uses expressions instead of absolute time numbers. TimeSerial函数返回一个时间, 表示15分钟前 (-15) 上午6小时 (12 - 6) 或上午5:45:00。The TimeSerial function returns a time for 15 minutes before (-15) six hours before noon (12 - 6), or 5:45:00 A.M.

TimeSerial(12 - 6, -15, 0)

当任何参数超过此参数的正常范围时,它会递增到下一个更大的单元(如果适当)。When any argument exceeds the normal range for that argument, it increments to the next larger unit as appropriate. 例如,如果您指定 75 分钟,则计算结果为 1 小时 15 分钟。For example, if you specify 75 minutes, it is evaluated as one hour and 15 minutes. 如果任意单个参数超出 -32,768 到 32,767 的范围,则将发生错误。If any single argument is outside the range -32,768 to 32,767, an error occurs. 如果由这三个参数指定的时间导致日期位于可接受的数据范围之外,则将发生错误。If the time specified by the three arguments causes the date to fall outside the acceptable range of dates, an error occurs.


此示例使用 TimeSerial 函数返回指定的小时、分钟和秒所对应的时间。This example uses the TimeSerial function to return a time for the specified hour, minute, and second.

Dim MyTime
MyTime = TimeSerial(16, 35, 17)    ' MyTime contains serial 
    ' representation of 4:35:17 PM.

另请参阅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.