VB 读取系统年月日

来源:百度知道 编辑:UC知道 时间:2024/05/30 09:33:49
请问VB要调用什么API函数才能读取系统时间?不是XX时:XX分之类的,而是XX年/XX月/XX日,这种格式的。

不需要用api函数的,直接用
format(date,"yy年mm月rr日")的格式就可以得到系统日期,如果非要用api函数,可以使用GetSystemTime或GetLocalTime,前者得到标准时间,
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Sub Macro1()
Dim sys As SYSTEMTIME
GetLocalTime sys
msgbox sys.year & "年" & sys.month & "月" & sys.day & "日"

Dim str1 As String
str1=Format(date,"yy年mm月dd日")

Format(Now(), "yyyy-mm-dd")