vb6 UTC time?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jhLewis

    #1

    vb6 UTC time?

    Using vb6, I would like to have either a text box or label display the
    current time in UTC format...I can't seem to find any instructions or code
    snippets on how to accomplish it...

    Any help appreciated...t hanks.

    John


  • Magnus McElroy

    #2
    Re: vb6 UTC time?



    jhLewis wrote:[color=blue]
    > Using vb6, I would like to have either a text box or label display the
    > current time in UTC format...I can't seem to find any instructions or code
    > snippets on how to accomplish it...
    >
    > Any help appreciated...t hanks.
    >
    > John[/color]


    I used this code. I cut-and-pasted it, so help yourself.

    'After this point, I cut and pasted code from a Visual Basic group to
    'try and help with the timezone problem.
    Const TIME_ZONE_ID_IN VALID = &HFFFFFFFF
    Const TIME_ZONE_ID_UN KNOWN = &H0
    Const TIME_ZONE_ID_ST ANDARD = &H1
    Const TIME_ZONE_ID_DA YLIGHT = &H2

    Type TIME_ZONE_INFOR MATION
    Bias As Long
    StandardName As String * 32
    StandardDate As Long
    StandardBias As Long
    DaylightName As String * 32
    DaylightDate As Long
    DaylightBias As Long
    End Type

    Declare Function GetTimeZoneInfo rmation Lib "kernel32" _
    (lpTimeZoneInfo rmation As TIME_ZONE_INFOR MATION) As Long

    Function NowPlusTZBias() As Date

    Dim usrTZI As TIME_ZONE_INFOR MATION
    Dim lngRetVal As Long

    lngRetVal = GetTimeZoneInfo rmation(usrTZI)
    NowPlusTZBias = Now + (usrTZI.Bias / 1440)
    End Function

    To use it in the program, do this:

    'If this is true, we're using Windows Time. Note that we have to
    'compenstate for the timezone and use UTC. The NowPlusTZ Biaswas
    'code taken from a MS access? newsgroup.
    data_out(1) = CByte(Year(NowP lusTZBias) - 2000)
    data_out(2) = CByte(Month(Now PlusTZBias))
    data_out(3) = CByte(Day(NowPl usTZBias))
    data_out(4) = CByte(Hour(NowP lusTZBias))
    data_out(5) = CByte(Minute(No wPlusTZBias))
    data_out(6) = CByte(Second(No wPlusTZBias))


    In other words, copy the first part into your code (as I did) and
    instead of using Now, use NowPlusTZBias

    --
    Magnus McElroy
    Electrical Engineer (EIT)
    HABIT Research
    (250) 381-9425

    Comment

    • Keith R. Weimer

      #3
      Re: vb6 UTC time?


      "Magnus McElroy" <"[myfirstname]"@habitresearch .[com]> wrote in message
      news:NyMMe.3473 5$vj.3766@pd7tw 1no...[color=blue]
      >
      >
      > jhLewis wrote:[color=green]
      >> Using vb6, I would like to have either a text box or label display the
      >> current time in UTC format...I can't seem to find any instructions or
      >> code snippets on how to accomplish it...
      >>
      >> Any help appreciated...t hanks.
      >>
      >> John[/color]
      >
      >
      > I used this code. I cut-and-pasted it, so help yourself.
      >
      > 'After this point, I cut and pasted code from a Visual Basic group to 'try
      > and help with the timezone problem.
      > Const TIME_ZONE_ID_IN VALID = &HFFFFFFFF
      > Const TIME_ZONE_ID_UN KNOWN = &H0
      > Const TIME_ZONE_ID_ST ANDARD = &H1
      > Const TIME_ZONE_ID_DA YLIGHT = &H2
      >
      > Type TIME_ZONE_INFOR MATION
      > Bias As Long
      > StandardName As String * 32
      > StandardDate As Long
      > StandardBias As Long
      > DaylightName As String * 32
      > DaylightDate As Long
      > DaylightBias As Long
      > End Type
      >
      > Declare Function GetTimeZoneInfo rmation Lib "kernel32" _
      > (lpTimeZoneInfo rmation As TIME_ZONE_INFOR MATION) As Long
      >
      > Function NowPlusTZBias() As Date
      >
      > Dim usrTZI As TIME_ZONE_INFOR MATION
      > Dim lngRetVal As Long
      >
      > lngRetVal = GetTimeZoneInfo rmation(usrTZI)
      > NowPlusTZBias = Now + (usrTZI.Bias / 1440)
      > End Function
      >
      > To use it in the program, do this:
      >
      > 'If this is true, we're using Windows Time. Note that we have to
      > 'compenstate for the timezone and use UTC. The NowPlusTZ Biaswas
      > 'code taken from a MS access? newsgroup.
      > data_out(1) = CByte(Year(NowP lusTZBias) - 2000)
      > data_out(2) = CByte(Month(Now PlusTZBias))
      > data_out(3) = CByte(Day(NowPl usTZBias))
      > data_out(4) = CByte(Hour(NowP lusTZBias))
      > data_out(5) = CByte(Minute(No wPlusTZBias))
      > data_out(6) = CByte(Second(No wPlusTZBias))
      >
      >
      > In other words, copy the first part into your code (as I did) and instead
      > of using Now, use NowPlusTZBias
      >
      > --
      > Magnus McElroy
      > Electrical Engineer (EIT)
      > HABIT Research
      > (250) 381-9425[/color]

      Is there a reason why seemingly nobody used the GetSystemTime funtion and
      does all this crazy adding and subtracting?

      Keith R. Weimer
      Way Too Happy Software


      Comment

      • Magnus McElroy

        #4
        Re: vb6 UTC time?



        Keith R. Weimer wrote:
        *snip*[color=blue]
        >
        >
        > Is there a reason why seemingly nobody used the GetSystemTime funtion and
        > does all this crazy adding and subtracting?
        >
        > Keith R. Weimer
        > Way Too Happy Software
        >[/color]

        Nope, no reason. It was just the first solution I found. It works, so
        there's no point in changing it.

        --
        Magnus McElroy
        Electrical Engineer (EIT)
        HABIT Research
        (250) 381-9425

        Comment

        Working...