|
本帖最后由 玉树TMD临风 于 2015-5-16 14:11 编辑
*************************很抱歉,应该是毫秒,不是微秒,谢谢3楼提醒***********************
近日在Access里需要读取系统的毫秒,开始以为A里也是用ms代表毫秒,用yyyymmddhhmmssms确实也出来一串时间,但仔细一看,后面的ms其实是m和s两个值。
论坛里没有找到关于毫秒的解决办法(查询“ms”网站就报错,可能有限制),在网上搜寻一番用API解决了,以下是源代码,放在模块里,然后在需要时间的地方调用=getdatetime即可。
Option Compare Database
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
Private Declare PtrSafe Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Public Function getdatetime() As String
Dim LCT As SYSTEMTIME
Dim ymd As String, hms As String
GetLocalTime LCT
ymd = Format(LCT.wYear & "-" & LCT.wMonth & "-" & LCT.wDay, "yyyyMMdd")
hms = Format(LCT.wHour, "00") & Format(LCT.wMinute, "00") & Format(LCT.wSecond, "00") & Format(LCT.wMilliseconds, "000")
getdatetime = ymd & hms
End Function
注意:type里的各个项目不能少,顺序也不能乱,不然结果就不对了。
|
|