VB 读取系统年月日

2024-11-28 21:00:43
推荐回答(3个)
回答1:

不需要用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 & "日"

回答2:

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

回答3:

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