VBS中formatdatetime函数怎么使用
在VBS中,FormatDateTime函数用于将日期和时间值格式化为字符串。它的语法如下:
FormatDateTime(date, format)
其中,date是日期和时间值,format是一个可选参数,用于指定返回字符串的格式。可用的格式值包括:
-
0或vbGeneralDate:默认值,返回日期和时间。 -
1或vbLongDate:返回长日期格式。 -
2或vbShortDate:返回短日期格式。 -
3或vbLongTime:返回长时间格式。 -
4或vbShortTime:返回短时间格式。
以下是一个示例:
Dim dt
dt = Now
WScript.Echo FormatDateTime(dt, 0) ' 输出日期和时间
WScript.Echo FormatDateTime(dt, 1) ' 输出长日期格式
WScript.Echo FormatDateTime(dt, 2) ' 输出短日期格式
WScript.Echo FormatDateTime(dt, 3) ' 输出长时间格式
WScript.Echo FormatDateTime(dt, 4) ' 输出短时间格式
运行以上代码,将输出当前日期和时间的不同格式化结果。
相关问答