Function f_fmt_date(dtmData) '格式化日期 2023-01-31
f_fmt_date = Year(dtmData) & "-" & Right("0" & Month(dtmData), 2) & "-" & Right("0" & Day(dtmData), 2)
End Function
Function f_fmt_time(dtmData) '格式化时间 08:01:01
f_fmt_time = Right("0" & Hour(dtmData), 2) & ":" & Right("0" & Minute(dtmData), 2) & ":" & Right("0" & Second(dtmData), 2)
End Function
Function f_date_now() '无误差日期+时间
theNow = Now() '定到一个值,而不是分开取date和time,那样不准
theNowDate = Year(theNow) & "-" & Right("0" & Month(theNow), 2) & "-" & Right("0" & Day(theNow), 2)
theNowTime = Right("0" & Hour(theNow), 2) & ":" & Right("0" & Minute(theNow), 2) & ":" & Right("0" & Second(theNow), 2)
f_date_now = theNowDate & " " & theNowTime
End Function
Function f_date_add(strType, intNum, strDateTime)
'f_date_add("d",-1,strDateTime) 减少1天
theNow = DateAdd(strType, intNum, strDateTime)
theNowDate = Year(theNow) & "-" & Right("0" & Month(theNow), 2) & "-" & Right("0" & Day(theNow), 2)
theNowTime = Right("0" & Hour(theNow), 2) & ":" & Right("0" & Minute(theNow), 2) & ":" & Right("0" & Second(theNow), 2)
f_date_add = theNowDate & " " & theNowTime
End Function
ASP调用:
<%
dtmData = Now
response.write f_fmt_date(dtmData) & " " & f_fmt_time(dtmData)
%>
VB6调用:
Private Sub Command1_Click()
Dim dtmData As Date
dtmData = Now
Debug.Print f_fmt_date(dtmData) & " " & f_fmt_time(dtmData)
End Sub
运行结果:
2023-1-31 21:49:38
命名规范参考《VB6 变量前缀命名规范和把类型符放在变量的尾部 String$ Integer% Long& Single! Double# Currency@》
当然VB6也可以:
Private Sub Command1_Click()
Debug.Print Format(Now, "yyyy-mm-dd hh:nn:ss")
End Sub