Results 1 to 3 of 3

Thread: Time

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    4

    Question

    How do I find out the current millisecond in VB? I know how to get the current hour, minute, and second, but how do I get the current millisecond?

    And also, how do I find the timezone offset in VB? For instance, mine is -3.5 (also known as GMT -3:30)

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    Sure!
    Code:
    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" (lpSystemTime As SYSTEMTIME)
    
    Private Sub Command1_Click()
        Dim udtTime As SYSTEMTIME
        
        
        Call GetSystemTime(udtTime)
        
        MsgBox udtTime.wHour & ":" & udtTime.wMinute & ":" & udtTime.wSecond & "." & udtTime.wMilliseconds
    End Sub

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    Ohh yeah, I forgot about the Time Zone. Here it is:
    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 Type TIME_ZONE_INFORMATION
            Bias As Long
            StandardName(32) As Integer
            StandardDate As SYSTEMTIME
            StandardBias As Long
            DaylightName(32) As Integer
            DaylightDate As SYSTEMTIME
            DaylightBias As Long
    End Type
    Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
    
    Private Sub Command1_Click()
        Dim udtTime As TIME_ZONE_INFORMATION
        Dim i As Integer
        Dim strBuffer As String
        Dim sngOffSet As Single
        Dim lngRet As Long
        
        lngRet = GetTimeZoneInformation(udtTime)
        If lngRet Then
            'Get offset number
            sngOffSet = (udtTime.Bias * -1) / 60
            
            'Convert byte array of ASCII characters to readable string
            For i = 0 To 32
                If udtTime.StandardName(i) = 0 Then Exit For
                strBuffer = strBuffer & Chr(udtTime.StandardName(i))
            Next
            MsgBox "Your Time Zone is: " & strBuffer & " (" & sngOffSet & ")"
        Else
            MsgBox "Error retrieving TimeZone information."
        End If
    End Sub

    Best regards,

    [Edited by Serge on 04-14-2000 at 08:40 PM]

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