Results 1 to 4 of 4

Thread: Is there any way to convert from UTC time to a standard date in VB?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    27
    Something like gmtime() or localtime() in C

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    UTC to Date

    Am I missing something or is that just a matter of taking the UTC value and adding this to January 1, 1970.

    Thats what UTC is meant to be anyhow. i.e. 00:00:01 UTC = 1 second after midnight on 1 Jan 1970.

    Do you need more help or is that enough of a clue for now

    Regards
    Paul Lewis

  3. #3
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    just in case

    Here is a sample piece of code to go from UTC to date.

    Form1 has Command1 button and Text1 and Text2 textboxes.
    type the UTC value in Text1 and hit the button.

    Code:
    Option Explicit
    
    Private Function UTCtoDate(utc As Double) as Date
      Dim utc0 As Date
      Dim mydate As Date
      utc0 = DateSerial(1970, 1, 1)
      ' 86400 = seconds in a day
      mydate = CDate(utc / 86400#) + utc0
      UTCtoDate = mydate
    End Function
    
    Private Sub Command1_Click()
      Text2.Text = UTCtoDate(CDbl(Text1.Text))
    End Sub

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    27
    that did it, thanks

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