Office中国论坛/Access中国论坛

标题: Access里使用API实现读取毫秒的方法 [打印本页]

作者: 玉树TMD临风    时间: 2015-5-14 22:37
标题: Access里使用API实现读取毫秒的方法
本帖最后由 玉树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里的各个项目不能少,顺序也不能乱,不然结果就不对了。





作者: tmtony    时间: 2015-5-14 23:33
{:soso_e179:}
玉树临风,赞一个!
作者: roych    时间: 2015-5-15 11:39
微秒?我觉得读到毫秒精度已经很高了。。。前段时间研究网站实时访客时,发现前端都是用New Date()来获取毫秒的




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3