Results 1 to 3 of 3

Thread: How to get Current Time in Millisecond

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    84

    How to get Current Time in Millisecond

    i am working with a winsock prog that send current time to server in millisecond

    how do i convert time to millisecond i have no idea how my current time =1254193889061

    1254193889061 <-- is my time few minutes ago


    plz help me with converting time to millisecond !!

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: How to get Current Time in Millisecond

    Here's one way:
    Code:
    Option Explicit
    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 Sub GetSystemTime Lib "kernel32.dll" (lpSystemTime As SYSTEMTIME)
    Private Declare Sub GetLocalTime Lib "kernel32.dll" (lpSystemTime As SYSTEMTIME)
    Private Sub Form_Load()
     Dim st As SYSTEMTIME
    ' GetSystemTime st     GMT
     GetLocalTime st
     Debug.Print st.wMonth, st.wDay, st.wYear
     Debug.Print st.wHour, st.wMinute, st.wSecond, st.wMilliseconds
    End Sub

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to get Current Time in Millisecond

    It appears your time is based off of a start date of 1 Jan 1970. In that case, you can also do this without APIs. Value will be large, so Double variable type could be appropriate.
    Code:
    MsgBox DateDiff("s", CDate("1/1/1970"), Now()) * 1000#
    ' Edited: If regional settings and date formats are a concern, use hardcoded value for 1/1/1970
    MsgBox DateDiff("s", 25569#, Now()) * 1000#
    Last edited by LaVolpe; Sep 29th, 2009 at 02:25 PM. Reason: added option to avoid regional-setting issues
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width