FormatDateTime
一个函数,这有助于在开发格中式化并返回一个有效的日期和时间表达式。
语法
FormatDateTime(date,format)
参数说明
-
date, 必需的参数。
-
format, 一个可选的参数。要使用指定的日期或时间格式值。它可以采用以下值:
-
0 = vbGeneralDate - 默认.
-
1 = vbLongDate - 返回时间
-
2 = vbShortDate - 返回时间
-
3 = vbLongTime - 返回时间
-
4 = vbShortTime - 返回时间
-
示例 :
添加一个按钮,并添加以下功能
Private Sub Constant_demo_Click() d=("2013-08-15 20:25") msgbox("Line 1 : " & FormatDateTime(d)) msgbox("Line 2 : " & FormatDateTime(d,1)) msgbox("Line 3 : " & FormatDateTime(d,2)) msgbox("Line 4 : " & FormatDateTime(d,3)) msgbox("Line 5 : " & FormatDateTime(d,4)) End Sub
当执行函数输出如下所示:
Line 1 : 15/08/2013 8:25:00 PM Line 2 : Thursday, 15 August 2013 Line 3 : 15/08/2013 Line 4 : 8:25:00 PM Line 5 : 20:25