Results 1 to 11 of 11

Thread: connecting to the internet's atomic clock

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Posts
    98

    Post

    does anyone know how to retrieve time from the internet atomic clock?

    --michael

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    what is the internet's atomic clock?? I've never heard of it...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Posts
    98

    Post

    it's the government's clock that uses atoms (somehow) to tell time. it is accurate to something like a billionth of a second. i have seen programs that connect to it to retrieve and set the time for their own computer. but since i am writing a clock program i just thought it might be a nice little added feature to add the ability to retrieve the "perfect atomic time" that's all.

    --michael

  4. #4
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Just a little note in case anyone is wondering. The atomic clock works by measuring the oscillations of certain elements like Cesium and Hydrogen. These clocks are accurate to about 1 second in a million years. One site you could check out is:
    http://www.cstv.to.cnr.it/toi/uk/atomtime.html

    ------------------
    Ryan
    [email protected]
    ICQ# 47799046

  5. #5
    Lively Member
    Join Date
    Sep 1999
    Location
    Guayaquil, Guayas, Ecuador
    Posts
    87

    Post

    http://www.eecis.udel.edu/~ntp/software.html
    tycho.usno.navy.mil

    look at this pages
    the first have some programs to retrive the time from the atomic clock

  6. #6
    Lively Member
    Join Date
    Sep 1999
    Location
    Guayaquil, Guayas, Ecuador
    Posts
    87

    Post

    http://www.mhn.org/~graham/nettime.html
    here are a code in c++ that do what you want

  7. #7
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    Ok, I think I figured it out.
    Draw a winsock control and a command button on a form, and paste the code. It will synchronize your system time with the atom clock of the nist institute.

    Code:
    Option Explicit
    Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
    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 Sub GetTime()
        Dim TimeOut As Boolean
        Dim StartTime As Single
        TimeOut = False
        StartTime = Timer
        Winsock1.RemoteHost = "time.nist.gov"
        Winsock1.RemotePort = 13
        Winsock1.Connect
        While (Not Winsock1.State = 7) Or TimeOut
            DoEvents
            TimeOut = Timer > StartTime + 5
        Wend
    End Sub
    
    Private Sub Command1_Click()
        Call GetTime
    End Sub
    
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
        Dim strData As String
        Winsock1.GetData strData, vbString
        Call SetTime(strData)
        Winsock1.Close
        Winsock1.LocalPort = 0
        Unload Me
    End Sub
    Private Sub SetTime(ByVal TimeString As String)
        Dim RetVal As Long
        Dim udtTime As SYSTEMTIME
        Dim TempDate As Date
        If Val(Mid(TimeString, 31, 1)) < 2 Then 'server is healthy enough
            TempDate = CDate(Val(Mid(TimeString, 2, 5)) - 15018)
            With udtTime
                .wYear = Year(TempDate)
                .wDayOfWeek = 0
                .wMonth = Month(TempDate)
                .wDay = Day(TempDate)
                .wHour = Val(Mid(TimeString, 17, 2))
                .wMinute = Val(Mid(TimeString, 20, 2))
                .wSecond = Val(Mid(TimeString, 23, 2))
                .wMilliseconds = 0
            End With
            RetVal = SetSystemTime(udtTime)
        End If
    End Sub

  8. #8
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    Just a silly question. Those atomic clocks are impressively accurate,
    but are there not huge delays in the net that you can not control?
    I used Tracert (in a DOS window) and noticed delays of several seconds.
    Don't those delays add to the retrieved time?

    [This message has been edited by Juan Carlos Rey (edited 12-10-1999).]

  9. #9
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    The Nist institute adds a certain time to compensate for network delays. But I'm sure the accuracy isn't the same as the clock itselve. However, I noticed the connection doesn't take seconds but just a second at the most. (the Netherlands to the US and back)

    [This message has been edited by Frans C (edited 12-11-1999).]

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Posts
    98

    Post

    damn Frans C...you are the man!! thank you so much. i have been trying to do this for a while now and kept screwing it up when it came to passing the retrieved time to my system's clock. thanks so very much for figuring this one out for me. liek i said...you are the man!!!

    --michael

  11. #11
    Guest

    Post

    Actually, I used the AtomTime98 program to match my computer clock with the atomic clock and It is almsot exact. If I look at my cable box my computer clock is about 1/2 a second differnt.

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