VBScript TimeSerial 函数

定义和用法

TimeSerial 函数可把时、分、秒合并成为时间。

注释:时分秒若超过应有的范围,其推算的原理与 DateSerial 相同。若经推算后得到的时间小于 #00:00:00#,则自动将负时间变为正时间;若经推算后得到的时间大于等于 #24:00:00#,则时间向前增加,使数据变成一个含有日期时间的数据,其中日期的起算日是 #12/30/1899#。

语法

TimeSerial(hour,minute,second)
参数 描述
hour 必需的。介于 0-23 的数字,或数值表达式。
minute 必需的。介于 0-59 的数字,或数值表达式。
second 必需的。介于 0-59 的数字,或数值表达式。

要指定一时刻,如 11:59:59,TimeSerial 的参数取值应在可接受的范围内;也就是说,小时应介于 0-23 之间,分和秒应介于 0-59 之间。但是,可以使用数值表达式为每个参数指定相对时间,这一表达式代表某时刻之前或之后的时、分或秒数。

When any parameter value exceeds the acceptable range, it will correctly roll over to the next larger time unit. For example, if 75 minutes are specified, this time is interpreted as one hour and fifteen minutes. However, if any parameter value exceeds the range of -32768 to 32767, an error will occur. If the time specified by three parameters directly or calculated by an expression exceeds the acceptable date range, an error will also occur.

Instance

Example 1

document.write(TimeSerial(9,30,50)) 'Normal calling method'

Output:

9:30:50 or 9:30:50 AM

Example 2

document.write(TimeSerial(0,9,11)) 'Normal calling method'

Output:

0:09:11 or 12:09:11 AM

Example 3

document.write(TimeSerial(14+2,9-2,1-1)) 'Output based on the result of the numerical expression'

Output:

16:07:00 or 4:07:00 PM

Example 4

document.write(TimeSerial(26,30,0)) 'Date starts from #12/30/1899# and increases by 1 day'

Output:

1899-12-31 2:30:00 AM