重拾VB之二,毫秒篇

重拾VB之二,毫秒篇

PMP 关劲松

   

    鬼使神差,09年12月入职的公司仍使用VB开发软件,虽然并非专职开发,但也不得不在事隔4年之后,重新使用VB。
    在vb中如何获得毫秒精度级别的时间?vb的时间函数不支持毫秒,需要利用windows的基本API,编写程序才能获取毫秒级别的时间精度。过程如下:   
    1 首先引入取系统时间方法,GetLocalTime,在"kernel32"中。
    2 然后定义一个结构,用于按年、月、日、小时、分钟、秒、毫秒保存时间。
    3 调用GetLocalTime,获取当前时间,保存到结构中。
    4 使用Format函数,生成时间的输出格式显示毫秒。

 

'代码如下:
'*-----------------------------------------------------------------------------*
'* 注释内容,建立结构体,用于按时间单位保存获取的系统时间。
 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
 
 '引入取系统时间方法,GetLocalTime
 Private Declare 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, "yyyy-MM-dd")
    hms = Format(LCT.wHour, "00") & ":" & Format(LCT.wMinute, "00") & ":" & Format(LCT.wSecond, "00") & "." & Format

(LCT.wMilliseconds, "000")
    getdatetime = ymd & " " & hms
    'MsgBox ymd & " " & hms
  End Function
'*-----------------------------------------------------------------------------*

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值