Announcement

Collapse
No announcement yet.

Time and Time again :)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Time and Time again :)

    OK So these threads and some free time I've had got me to looking at my silly Nuclear Time Server that I started last year...(It's humorous but it works)..

    Anyway, so I am OUTPUTTING NIST time now, and I have most of the functions already in place minus one...

    Determining if it is daylight savings time or not, or how to determine how many days until it reaches daylight savings time if we are in the month of DST conversion (Or back to Standard time)...

    Is there an API call to do this or is thhis guesswork based on a numbered date?

    Scott

    -------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    #2
    Scott,

    Doesn't the setSystemTime api function handle this automatically?

    Scott
    Scott Wolfington
    [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

    Comment


      #3
      Scott,

      Here's one...

      I want to get the difference between my system's time and the time server's time. I'd like to get this value in seconds. How do I go about subtracting two SYSTEMTIME's? I'm assuming I'd have to convert both times to FILETIME's. Not sure what's involved though.

      Thanks,
      Scott


      ------------------
      Scott Wolfington
      [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

      Comment


        #4
        Try this This is my thread code for updating the systemtime and displaying it to the textbox (you may have to change your variables etc for control handles
        Code:
        '-----------------------------------------------------------------------------------
        Function InitThread(ByVal x As Long) As Long
        Local TdSt          As String
        Local TmpSt         As String
        Local Year          As String
        Local Month         As String
        Local Day           As String
        Local Hour          As String
        Local Minute        As String
        Local Second        As String
        Local s             As String
        Local Y             As Long
        Local Start         As Long
        Local vbDate        As Double       '**DNJ**
        Local Delay         As Double
        Local st            As SYSTEMTIME   '**DNJ**
        Local bc            As SYSTEMTIME 'Buffer BEFORE CHANGE
        Local ac            As SYSTEMTIME 'Compare to AFTER CHANGE
        Year   = " Year"
        Month  = " Month"
        Day    = " Day"
        Hour   = " Hour"
        Minute = " Minute"
        Second = " Second"
        s      = "s"
        
        
        MousePtr 11
        Menu Set State mMenu,%IDM_ACHECK,%MF_DISABLED
        Menu Set State pMenu,%IDM_ACHECK,%MF_DISABLED
        Control Set Text hDlg, %PCTIME,""
        Control Set Text hDlg, %ATOMTIME,""
        Control Set Text hDlg, %ID_NETDELAY,""
        
        'Call the AtomicTime in DLL here....
        PCTime = GetPCTimeandDate(DateFormat,TimeFormat," ",tzinfo)
        If IsTrue SoundFlag Then Result = PlayWavFromResource(hInstance,WAVE + "2",WAV + "02")
        
        GetLocalTime bc 'BEFORE CHANGE
        
        MousePtr 11
        UTCTime = CheckAtomicTime(nServer,Val(AtomPort),aTimeOut, Delay,st)
        MousePtr 0
        If IsTrue SoundFlag Then Result = PlayWavFromResource(hInstance,WAVE + "3",WAV + "03")
        
        Statistics.AtomicChecked = Statistics.AtomicChecked + 1
        Control Set Text hDlg, %ID_STATSTEXT2,Trim$(Str$(Statistics.AtomicChecked))
        Control Set Text hDlg, %PCTIME,PCTime
        Control Set Text hDlg, %ATOMTIME,UTCTime
        Control Set Text hDlg, %ID_NETDELAY,Trim$(Str$(Delay)) + " ms"
        
        If IsTrue UseLog Then
           LogEvent "**** Check Atomic Clock ****"
           LogEvent "PC Time:       " + PCTime
           LogEvent "Atomic Time:   " + UTCTime
           LogEvent "Network Delay: " + Trim$(Str$(Delay)) + " ms"
        End If
        
        If SoundFlag =  -999 Then SoundFlag = %TRUE 'Re-enable sound
        'NIST TIME SERVER (Nuclear)
        '51468 99-10-17 05:12:27 15 0 0 888.6 UTC(NIST) *
        If Right$(UTCTime,2) = "* " Then
            ' Convert date and time to a SYSTEMTIME structure using a date VARIANT
            vbDate = StrToVbDate(Parse$(UTCTime, Any " ",2) + " " + Parse$(UTCTime, Any " ",3))
            VariantTimeToSystemTime vbDate, st
        ElseIf Len(UTCTime) = 5 Then
             RFC868toSystemTime CvDwd(UTCTime), st
        'ElseIf
           'Internet Time Server
           '"Wed, 13 Oct 1999 15:07:52 -0700"
        ElseIf Len(UTCTime) < 2 Then
            Function = 0
            Exit Function
        End If
        
        'Verify we are running on Windows Server
        osinfo.dwOsVersionInfoSize = SizeOf(osinfo)
        GetVersionEx osinfo
        If osinfo.dwPlatformId = %VER_PLATFORM_WIN32_NT Then
            ' Verify We're running Windows NT, adjust the process' token so that we can Set the time
            If IsTrue SetTimePrivilege Then
                Result = SendMessage(%HWND_BROADCAST, %WM_TIMECHANGE, 0, 0)
                Result = SetSystemTime(st)
            '   Use this for troubleshooting format only
            '    Control Set Text hDlg, %PCTIME,FormatOutPut(1) 'After adjustment
            Else
               Control Set Text hDlg, %PCTIME,"Error setting time! "
               Control Set Text hDlg, %ATOMTIME,"Could not gain rights to change the time"
               Exit Function
            End If
        Else
            Result = SendMessage(%HWND_BROADCAST, %WM_TIMECHANGE, 0, 0)
            Result = SetSystemTime(st)
        End If
        
        'Use this code to display the time difference:
        GetLocalTime ac
        
        ac.wyear    = Abs(bc.wyear - ac.wyear)
        ac.wmonth   = Abs(bc.wmonth - ac.wmonth)
        ac.wday     = Abs(bc.wday - ac.wday)
        ac.wHour    = Abs(bc.whour - ac.whour)
        ac.wMinute  = Abs(bc.wMinute - ac.wminute)
        ac.wsecond  = Abs(bc.wsecond - ac.wsecond)
        If ac.wyear   <> 1 Then Year = Year + s
        If ac.wmonth  <> 1 Then Month = Month + s
        If ac.wday    <> 1 Then Day = Day + s
        If ac.wHour   <> 1 Then Hour = Hour + s
        If ac.wMinute <> 1 Then Minute = Minute + s
        If ac.wsecond <> 1 Then Second = Second + s
        
        TdSt = Trim$(Str$(ac.wyear)) + Year + " " + Trim$(Str$(ac.wmonth)) + Month + " " + Trim$(Str$(ac.wday)) + Day + " " +_
               Trim$(Str$(ac.whour)) + Hour + " " + Trim$(Str$(ac.wminute)) + Minute + " " + Trim$(Str$(ac.wsecond)) + Second + " "
        Control Set Text hDlg, %IDTIMEDIFF, TdSt
        
        
        Menu Set State mMenu,%IDM_ACHECK,%MF_ENABLED
        Menu Set State pMenu,%IDM_ACHECK,%MF_ENABLED
        
        'Set Global Flag to False here
        g_lngInitThreadHandle = %FALSE
        End Function

        ------------------
        Scott
        mailto:[email protected][email protected]</A>

        [This message has been edited by Scott Turchin (edited April 08, 2000).]
        Scott Turchin
        MCSE, MCP+I
        http://www.tngbbs.com
        ----------------------
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎