Jump to content

Retrieve internet clock time?


Recommended Posts

Hello! :)

I am trying to retrieve from the internet and display GMT standard time in realtime on my program

Maybe from a site such as: http://wwp.greenwichmeantime.com/info/current-time/

From that retrieved time I would like to be able to perform an action based on what time it is.

For example:

If it is GMT 10:01:30, I would like to be able to set a time to perform the action at, say, 10:02:00

If you guys need more information about my request please ask.

Thank you,

-Vicate

Link to comment
Share on other sites

I'm setting my computers clock at boot time by this script.

Perhaps it can give you a starting point.

; Set Date and Time from Internet
; this code is derived from:
; www.autoitscript.com/forum/topic/43079-ntp-c-to-autoit-conversvion/page__view__findpost__p__765481

#include <Date.au3>

$ntpServer = "de.pool.ntp.org"
$socket = False
OnAutoItExitRegister("Cleanup")
Func Cleanup()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc   ;==>Cleanup

While Sleep(1000)
    UDPStartup()
    $socket = UDPOpen(TCPNameToIP($ntpServer), 123)
    If @error Then
        UDPShutdown()
        ContinueLoop
    EndIf
    UDPSend($socket, MakePacket("1b0e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"))
    If @error Then
        UDPCloseSocket($socket)
        UDPShutdown()
        ContinueLoop
    EndIf
    $data = ""
    While $data = ""
        $data = UDPRecv($socket, 100)
        Sleep(100)
    WEnd
    UDPCloseSocket($socket)
    UDPShutdown()
    ExitLoop
WEnd


;MsgBox(0, "UDP DATA RAW", $data)
$unsignedHexValue = StringMid($data, 83, 8); Extract time from packet. Disregards the fractional second.
;MsgBox(0, "UDP DATA", $unsignedHexValue)

$value = UnsignedHexToDec($unsignedHexValue)
$TZinfo = _Date_Time_GetTimeZoneInformation()
;$TZoffset = $TZinfo[1] * - 1
$UTC = _DateAdd("s", $value, "1900/01/01 00:00:00")

If $TZinfo[0] <> 2 Then ; 0 = Daylight Savings not used in current time zone / 1 = Standard Time
    $TZoffset = ($TZinfo[1]) * - 1
Else ; 2 = Daylight Savings Time
    $TZoffset = ($TZinfo[1] + $TZinfo[7]) * - 1
EndIf

;~ Extracts the data & time into vars
;~ Date format & offsets
;~ 2009/12/31 19:26:05
;~ 1234567890123456789  [1 is start of string]

$m = StringMid($UTC, 6, 2)
$d = StringMid($UTC, 9, 2)
$y = StringMid($UTC, 1, 4)
$h = StringMid($UTC, 12, 2)
$mi = StringMid($UTC, 15, 2)
$s = StringMid($UTC, 18, 2)

;~ MsgBox(0,"",$m & "/" & $d & "/" & $y & " " & $h & ":" & $mi & ":" & $s) ; Visual test of obtained date

;~ Sets the new current time to the computer
$tCurr = _Date_Time_EncodeSystemTime($m, $d, $y, $h, $mi, $s)
_Date_Time_SetSystemTime(DllStructGetPtr($tCurr))


;**************************************************************************************************
;** Fuctions **************************************************************************************
;**************************************************************************************************
Func MakePacket($d)
    Local $p = ""
    While $d
        $p &= Chr(Dec(StringLeft($d, 2)))
        $d = StringTrimLeft($d, 2)
    WEnd
    Return $p
EndFunc   ;==>MakePacket
;**************************************************************************************************
Func UnsignedHexToDec($n)
    $ones = StringRight($n, 1)
    $n = StringTrimRight($n, 1)
    Return Dec($n) * 16 + Dec($ones)
EndFunc   ;==>UnsignedHexToDec
;**************************************************************************************************
Edited by forumer100

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Thank you, Forumer. I will try to use that script as a starting point.

I see that it is able to retrieve the time as I wanted. I'll just keep working to figure out how to just display the time in a GUI and constantly refresh.

I'll check back with an update on my progress.

If anybody else can contribute to this you are more than welcome.

Thanks again,

-Vicate

Link to comment
Share on other sites

Okay, thanks to Forumer's script, I've gotten it to display the retrieved information on the GUI but it only refreshes to get one time (appears to be at the time of opening the program)

I only have it displaying the second value, mainly because it changes the most frequently.

I would like it to constantly refresh so it keeps displaying the changing time (so the seconds keep counting up)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <IE.au3>
Opt("TrayIconHide", 1)
$dll = DllOpen("user32.dll")
$Status = 'Off'
$Sustain = 'Off'

#Region ###
$Form1_1 = GUICreate("Test", 116, 25)
GUISetFont(8, 400, 0, "Arial")
GUISetBkColor(0xFFFFFF)
$Test = GUICtrlCreateLabel("", 8, 5, 84, 15, $WS_GROUP)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-2, 0x006633)
GUISetState(@SW_SHOW)
#EndRegion ### 

;=================

; Set Date and Time from Internet
; this code is derived from:
; www.autoitscript.com/forum/topic/43079-ntp-c-to-autoit-conversvion/page__view__findpost__p__765481

#include <Date.au3>

$ntpServer = "de.pool.ntp.org"
$socket = False
OnAutoItExitRegister("Cleanup")
Func Cleanup()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc   ;==>Cleanup

While Sleep(1000)
    UDPStartup()
    $socket = UDPOpen(TCPNameToIP($ntpServer), 123)
    If @error Then
        UDPShutdown()
        ContinueLoop
    EndIf
    UDPSend($socket, MakePacket("1b0e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"))
    If @error Then
        UDPCloseSocket($socket)
        UDPShutdown()
        ContinueLoop
    EndIf
    $data = ""
    While $data = ""
        $data = UDPRecv($socket, 100)
        Sleep(100)
    WEnd
    UDPCloseSocket($socket)
    UDPShutdown()
    ExitLoop
WEnd


;MsgBox(0, "UDP DATA RAW", $data)
$unsignedHexValue = StringMid($data, 83, 8); Extract time from packet. Disregards the fractional second.
;MsgBox(0, "UDP DATA", $unsignedHexValue)

$value = UnsignedHexToDec($unsignedHexValue)
$TZinfo = _Date_Time_GetTimeZoneInformation()
;$TZoffset = $TZinfo[1] * - 1
$UTC = _DateAdd("s", $value, "1900/01/01 00:00:00")

If $TZinfo[0] <> 2 Then ; 0 = Daylight Savings not used in current time zone / 1 = Standard Time
    $TZoffset = ($TZinfo[1]) * - 1
Else ; 2 = Daylight Savings Time
    $TZoffset = ($TZinfo[1] + $TZinfo[7]) * - 1
EndIf

;~ Extracts the data & time into vars
;~ Date format & offsets
;~ 2009/12/31 19:26:05
;~ 1234567890123456789  [1 is start of string]

$tm = StringMid($UTC, 6, 2)
$td = StringMid($UTC, 9, 2)
$ty = StringMid($UTC, 1, 4)
$th = StringMid($UTC, 12, 2)
$tmi = StringMid($UTC, 15, 2)
$ts = StringMid($UTC, 18, 2)

;~ MsgBox(0,"",$m & "/" & $d & "/" & $y & " " & $h & ":" & $mi & ":" & $s) ; Visual test of obtained date

;~ Sets the new current time to the computer
;$tCurr = _Date_Time_EncodeSystemTime($tm, $td, $ty, $th, $tmi, $ts)
;_Date_Time_SetSystemTime(DllStructGetPtr($tCurr))


;**************************************************************************************************
;** Fuctions **************************************************************************************
;**************************************************************************************************
Func MakePacket($d)
    Local $p = ""
    While $d
        $p &= Chr(Dec(StringLeft($d, 2)))
        $d = StringTrimLeft($d, 2)
    WEnd
    Return $p
EndFunc   ;==>MakePacket
;**************************************************************************************************
Func UnsignedHexToDec($n)
    $ones = StringRight($n, 1)
    $n = StringTrimRight($n, 1)
    Return Dec($n) * 16 + Dec($ones)
EndFunc   ;==>UnsignedHexToDec
;**************************************************************************************************

;==========

While 1
    $nMsg = GUIGetMsg()
        If $nMsg = $GUI_EVENT_CLOSE Then
            Exit
        EndIf
    GUICtrlSetData($Test, $ts)
Wend

Edit: So it looks like the problem is it isn't constantly querying the server. Is there a way to have it automatically query the server, say, every 300ms? Thanks.

Edited by Vicate
Link to comment
Share on other sites

While doing it in the raw is nice, http://www.nist.gov/pml/div688/grp40/its.cfm is a good source for an atomic clock and then you could adjust the output retrieved. *shrug*

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

The time syncronisation is only needed once a day. After sync you can use timingservices in Autoit.

See Timers Management in the help file.

You can also use Windows timer service to adjust the time. Here is the syntax:

Run(@ComSpec & " /c " & 'w32tm /resync /nowait', "", @SW_HIDE)

Edited by forumer100

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

I wasn't looking for a way to sync my computer's clock to the internet clock, but I suppose it is possible to achieve the same using a synced local time. The program I am writing requires multiple computers to be perfectly in sync time-wise so that they can perform an action at the same exact time. I figured if they're synced to an internet clock it would be more accurate, but I'd imagine that if the computers' local clocks are all synced to an internet time it would hopefully yield the same results.

When I get home I will check it out and come back w/ an update :]

Thanks again guys.

Link to comment
Share on other sites

This all depends on how much accuracy is required, and for what purpose. Retrieving any information from the internet will involve a time lag. If a very high level of synchronization is required, then it seems to me that the computers would have to be linked directly to each other.

Edited by czardas
Link to comment
Share on other sites

I'm working with a midi mixer/sequencer with FL Studio and am using the computers to play different parts of a song which are transmitted online. I am "playing" the song with my friend who lives approx. 5 miles away. When we want to play together, we do something along the lines of "3, 2, 1, go" on the phone and both click play at the same exact time. It would be much, much easier if I could write something that syncs to an internet clock and we could set a time to click "play" when the internet clock reaches that specific time.

There is a little "wiggle room" for the accuracy but I wouldn't want there to be more than a 300ms delay, if that.

To be too terribly off would mean that one computer is "playing" their parts behind the other.

Edited by Vicate
Link to comment
Share on other sites

I'm working with a midi mixer/sequencer with FL Studio and am using the computers to play different parts of a song which are transmitted online. I am "playing" the song with my friend who lives approx. 5 miles away. When we want to play together, we do something along the lines of "3, 2, 1, go" on the phone and both click play at the same exact time. It would be much, much easier if I could write something that syncs to an internet clock and we could set a time to click "play" when the internet clock reaches that specific time.

There is a little "wiggle room" for the accuracy but I wouldn't want there to be more than a 300ms delay, if that.

To be too terribly off would mean that one computer is "playing" their parts behind the other.

300 miliseconds is a lot IMO. I'm not sure about transfer rates, but they will certainly vary. If you shut down unecessary processes on both computers and run some tests, you might be able to determine an average delay time and somehow use the information to get better synchronization. An alternative might be to play music in a loop sequence, when the delay will be less of an issue.
Link to comment
Share on other sites

I just measured the roundtriptime. Time between sending the request and getting the answer.

On my location, it is 125 Milliseconds.

You and your friend should measure your roundtriptimes and the difference between your times is your actual difference. Since you are located nearby, it should be very small.

Perhaps you should choose a different NTP server. Mine is in Germany ("de.pool.ntp.org").

Here the code to show the roundtriptime.

; Set Date and Time from Internet
; this code is derived from:
; http://www.autoitscript.com/forum/topic/43079-ntp-c-to-autoit-conversvion/page__view__findpost__p__765481

#include <Date.au3>

$ntpServer = "de.pool.ntp.org"
$socket = False
OnAutoItExitRegister("Cleanup")
Func Cleanup()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc   ;==>Cleanup

While Sleep(1000)
    UDPStartup()
    $socket = UDPOpen(TCPNameToIP($ntpServer), 123)
    If @error Then
        UDPShutdown()
        ContinueLoop
    EndIf
    $timer = TimerInit()
    UDPSend($socket, MakePacket("1b0e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"))
    If @error Then
        UDPCloseSocket($socket)
        UDPShutdown()
        ContinueLoop
    EndIf
    $data = ""
    While $data = ""
        $data = UDPRecv($socket, 100)
        Sleep(100)
    WEnd
    $diff = TimerDiff($timer)
    UDPCloseSocket($socket)
    UDPShutdown()
    ExitLoop
WEnd


;MsgBox(0, "UDP DATA RAW", $data)
$unsignedHexValue = StringMid($data, 83, 8); Extract time from packet. Disregards the fractional second.
;MsgBox(0, "UDP DATA", $unsignedHexValue)

$value = UnsignedHexToDec($unsignedHexValue)
$TZinfo = _Date_Time_GetTimeZoneInformation()
;$TZoffset = $TZinfo[1] * - 1
$UTC = _DateAdd("s", $value, "1900/01/01 00:00:00")

If $TZinfo[0] <> 2 Then ; 0 = Daylight Savings not used in current time zone / 1 = Standard Time
    $TZoffset = ($TZinfo[1]) * - 1
Else ; 2 = Daylight Savings Time
    $TZoffset = ($TZinfo[1] + $TZinfo[7]) * - 1
EndIf

;~ Extracts the data & time into vars
;~ Date format & offsets
;~ 2009/12/31 19:26:05
;~ 1234567890123456789  [1 is start of string]

$m = StringMid($UTC, 6, 2)
$d = StringMid($UTC, 9, 2)
$y = StringMid($UTC, 1, 4)
$h = StringMid($UTC, 12, 2)
$mi = StringMid($UTC, 15, 2)
$s = StringMid($UTC, 18, 2)

;~ MsgBox(0,"",$m & "/" & $d & "/" & $y & " " & $h & ":" & $mi & ":" & $s) ; Visual test of obtained date

;~ Sets the new current time to the computer
$tCurr = _Date_Time_EncodeSystemTime($m, $d, $y, $h, $mi, $s)
_Date_Time_SetSystemTime(DllStructGetPtr($tCurr))
MsgBox(262144, "", @LF & $diff & " Milliseconds roundtriptime" & @LF, 10)


;**************************************************************************************************
;** Fuctions **************************************************************************************
;**************************************************************************************************
Func MakePacket($d)
    Local $p = ""
    While $d
        $p &= Chr(Dec(StringLeft($d, 2)))
        $d = StringTrimLeft($d, 2)
    WEnd
    Return $p
EndFunc   ;==>MakePacket
;**************************************************************************************************
Func UnsignedHexToDec($n)
    $ones = StringRight($n, 1)
    $n = StringTrimRight($n, 1)
    Return Dec($n) * 16 + Dec($ones)
EndFunc   ;==>UnsignedHexToDec
;**************************************************************************************************

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Since you are located nearby, it should be very small.

Physical locations don't always mean much with latency, unless they're in the same building on the same network. 2 people on the same ISP can have a greater latency than 2 people on different ISPs, it all depends on what they have to go through to get from one computer to the other.

I used to play online with some friends in a different location from me, about 200 miles apart from each other, and we all were connecting to a server that was hosted by their ISP and I had better ping/latency than they did.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Okay I have figured out a way to get what I want to some extent.

When synced, the most the times are off by is +- 1sec.

For that reason I have created an "offset" feature that sets it off, the only problem now is that if the second value is less than 10 or at 59, the sum or difference is expressed numerically.

Examples:

On offset -1, "10:00:00" is expressed as "10:00:-1" instead of "09:59:59"

On offset -1, "10:00:02" is expressed as "10:00:1" instead of "10:00:01"

On offset +1, "10:00:59" is expressed as "10:00:60" instead of "10:01:00"

I mean it makes sense why it would do that but how would I make it correctly express the offsets?

I know it is now unrelated to the topic but I don't see the sense in flooding the forums with another thread if it is a quick fix.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <Date.au3>
#RequireAdmin
DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1) ; This disables 32bit applications from being redirected to syswow64 instead of system32 by default ;
Opt("TrayIconHide", 1)
$dll = DllOpen("user32.dll")
$TStatus = 'Off'
$Offset = '0'

#Region ###
$Form1_1 = GUICreate("Timer", 215, 165)
GUISetFont(8, 400, 0, "Arial")
GUISetBkColor(0xFFFFFF)
;CLOCK STUFF
$Group2 = GUICtrlCreateGroup("Time", 110, 5, 100, 155)
GUICtrlSetColor(-1, 0xC0C0C0)
$TOn = GUICtrlCreateLabel("    On", 117, 66, 41, 15, $WS_GROUP)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-2, 0x000000)
$TOff = GUICtrlCreateLabel("    Off", 160, 66, 41, 15, $WS_GROUP)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x006633)
$Time1 = @HOUR & ":" & @MIN & ":" & @SEC
$Time2 = GUICtrlCreateLabel($Time1, 135, 21, 42, 15)
$Sync = GUICtrlCreateLabel("     Sync Time", 117, 85, 84, 15)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-2, 0x000000)
GUICtrlCreateLabel("If timer is set to 'on' Player will start at:" , 115, 102, 90, 30)
;Time Format:HH:MM:SS
$Hour = StringMid(GUICtrlRead($Time2), 1, 2)
$Min = StringMid(GUICtrlRead($Time2), 4, 2)
$Sec = StringMid(GUICtrlRead($Time2), 7, 2)
$SetHour = GuiCtrlCreateInput("" & @HOUR, 118, 130, 25, 20)
$SetMin = GuiCtrlCreateInput("" & @MIN, 148, 130, 25, 20)
$SetSec = GuiCtrlCreateInput("" & @SEC, 178, 130, 25, 20)
$OffSet1 = GUICtrlCreateRadio( "", 125, 36, 15, 15)
$OffSet2 = GUICtrlCreateRadio( "", 150, 36, 15, 15)
$OffSet3 = GUICtrlCreateRadio( "", 175, 36, 15, 15)
GUICtrlCreateLabel("-1      0      +1", 125, 50, 65, 15)
GUICtrlSetState($Offset2, $GUI_CHECKED)
;END CLOCK
GUISetState(@SW_SHOW)
#EndRegion ### 

Func _SyncPlay()
    If ($Hour = GUICtrlRead($SetHour)) and ($Min = GUICtrlRead($SetMin)) and ($Sec = GUICtrlRead($SetSec)) Then
        MsgBox(1, "Title", "Time met, perform action") ;Testing feedback
        ;MouseClick("left", 140, 210, 1, 1) ;Perform MouseClick
        Sleep(1001)
    EndIf
EndFunc

While 1
    $nMsg = GUIGetMsg()
        If $nMsg = $GUI_EVENT_CLOSE Then
            Exit
        EndIf
        
        ;CLOCK STUFF
        If GUICtrlRead($Offset1) = $GUI_CHECKED Then
            $Offset = '-1'
        EndIf
        If GUICtrlRead($Offset2) = $GUI_CHECKED Then
            $Offset = '0'
        EndIf
        If GUICtrlRead($Offset3) = $GUI_CHECKED Then
            $Offset = '1'
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & @SEC) and $Offset = '0' Then
            $Time1 = @HOUR & ":" & @MIN & ":" & @SEC
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-1)) and $Offset = '-1' Then
            $Time1 = @HOUR & ":" & @MIN & ":" & (@SEC-1)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+1)) and $Offset = '1' Then
            $Time1 = @HOUR & ":" & @MIN & ":" & (@SEC+1)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
        EndIf
        If $nMsg = $Sync Then
        Run(@ComSpec & ' /c w32tm /resync')
        GUICtrlSetData($SetHour, $Hour)
        GUICtrlSetData($SetMin, $Min)
        GUICtrlSetData($SetSec, $Sec)
        EndIf
        ;END CLOCK
        
        If ($nMsg = $TOn or _IsPressed('DC', $dll)) and $TStatus = 'Off' Then
            GUICtrlSetBkColor($TOn, 0x006633)
            GUICtrlSetBkColor($TOff, 0x000000)
            $TStatus = 'On'
            Sleep(200)
        EndIf
        If ($nMsg = $TOff or _IsPressed('DC', $dll)) and $TStatus = 'On' Then
            GUICtrlSetBkColor($TOn, 0x000000)
            GUICtrlSetBkColor($TOff, 0x006633)
            $TStatus = 'Off'
            Sleep(200)
        EndIf
        If $TStatus = 'On' Then
            _SyncPlay()
        ElseIf $TStatus = 'Off' Then
        EndIf
WEnd

I know I can do it by adding conditions such as:

;##OFFSET -1##
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-1)) and $Offset = '-1' and ((@SEC) <> 00) and ((@SEC) < 11) Then;for seconds 0-59
            $Time1 = @HOUR & ":" & @MIN & ":0" & (@SEC-1)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-1)) and $Offset = '-1' and ((@SEC) > 10) Then;for seconds 10-58
            $Time1 = @HOUR & ":" & @MIN & ":" & (@SEC-1)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-1)) and $Offset = '-1' and ((@SEC) = 00) Then;for second 59
            $Time1 = @HOUR & ":" & (@MIN-1) & ":59"
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
        EndIf
        ;#OFFSET -1##
        
        ;#OFFSET +1##
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+1)) and $Offset = '+1' and ((@SEC) = 59) Then;for second 00
            $Time1 = @HOUR & ":" & (@MIN+1) & ":" & "00"
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+1)) and $Offset = '+1' and ((@SEC) < 9) Then;for seconds 1-9
            $Time1 = @HOUR & ":" & @MIN & ":0" & (@SEC+1)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+1)) and $Offset = '+1' and ((@SEC) > 8) and ((@SEC) < 59) Then;for seconds 10-59
            $Time1 = @HOUR & ":" & @MIN & ":" & (@SEC+1)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
        EndIf
        ;##OFFSET +1##

In which case the only problem would occur at the 59 min mark, but that also could be fixed w/ even more conditions.

Just wondering if there were an easier way to do it.

Thank you in advance :)

-Vicate

Edited by Vicate
Link to comment
Share on other sites

Might be easier :)

Local $time = "04:34:59", $diff = "1"
ConsoleWrite(@LF & $time &" Diff: "&$diff& @LF & _TimeAdd($time, $diff) &" DayDiff: "&@extended& @LF & @LF)
Local $time = "00:00:00", $diff = -1
ConsoleWrite(@LF & $time &" Diff: "&$diff& @LF & _TimeAdd($time, $diff) &" DayDiff: "&@extended& @LF & @LF)
Local $time = "23:59:59", $diff = 1
ConsoleWrite(@LF & $time &" Diff: "&$diff& @LF & _TimeAdd($time, $diff) &" DayDiff: "&@extended& @LF & @LF)
Exit

Func _TimeAdd($time, $diff)
    $a = StringSplit($time, ":")
    $sec = 24 * 3600 + $a[1] * 3600 + $a[2] * 60 + $a[3] + $diff
    $s = _Mod($sec, 60)
    $m = _Mod(@extended, 60)
    $h = _Mod(@extended, 24)
    Return SetError(0, @extended -1 ,StringFormat("%02s:%02s:%02s", $h, $m, $s))
EndFunc   ;==>_TimeAdd

Func _Mod($dividend, $divisor = 10) ; by forumer100. Added @extended = quotient and default divisor = 10
    If $divisor = 0 Then Return SetError(1, "", -1)
    $quotient = Int($dividend / $divisor)
    $remainder = $dividend - $quotient * $divisor
    Return SetError(0, $quotient, $remainder)
EndFunc   ;==>_Mod
Edited by forumer100

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <Date.au3>
#RequireAdmin
DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1) ; This disables 32bit applications from being redirected to syswow64 instead of system32 by default ;

Opt("TrayIconHide", 1)
$dll = DllOpen("user32.dll")
$CStatus = 'Off'
$CMode = '1'

#Region ###
$Form1_1 = GUICreate("Timertest", 215, 225)
GUISetFont(8, 400, 0, "Arial")
GUISetBkColor(0xFFFFFF)

;CLOCK STUFF
$Group2 = GUICtrlCreateGroup("Time", 110, 5, 100, 215)
GUICtrlSetColor(-1, 0xC0C0C0)
$TOn = GUICtrlCreateLabel("    On", 117, 126, 41, 15, $WS_GROUP)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-2, 0x000000)
$TOff = GUICtrlCreateLabel("    Off", 160, 126, 41, 15, $WS_GROUP)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x006633)
$Time1 = @HOUR & ":" & @MIN & ":" & @SEC
$Time2 = GUICtrlCreateLabel($Time1, 135, 21, 42, 15)
$Sync = GUICtrlCreateLabel("     Sync Time", 117, 145, 84, 15)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-2, 0x000000)
GUICtrlCreateLabel("If timer is set to 'on' Player will start at:" , 115, 162, 90, 30)
;Time Format:HH:MM:SS
$Hour = StringMid(GUICtrlRead($Time2), 1, 2)
$Min = StringMid(GUICtrlRead($Time2), 4, 2)
$Sec = StringMid(GUICtrlRead($Time2), 7, 2)
$Check = StringMid(GUICtrlRead($Time2), 8, 1)
$SetHour = GuiCtrlCreateInput("" & @HOUR, 118, 190, 25, 20)
$SetMin = GuiCtrlCreateInput("" & @MIN, 148, 190, 25, 20)
$SetSec = GuiCtrlCreateInput("" & @SEC, 178, 190, 25, 20)
$OffSet = GUICtrlCreateSlider(115, 76, 90, 20)
GUICtrlSetBkColor(-2, 0xFFFFFF)
GUICtrlSetLimit(-1, 40, 0)
GUICtrlSetData(-1, 0)
$OffSetAmt = GUICtrlCreateLabel("0", 147, 100, 50, 10)
GUICtrlCreateLabel("0", 120, 105, 15, 10)
GUICtrlCreateLabel("+1", 187, 105, 15, 10)
$OffSet0 = GUICtrlCreateRadio( "", 120, 36, 15, 15)
$OffSet1 = GUICtrlCreateRadio( "", 135, 36, 15, 15)
$OffSet2 = GUICtrlCreateRadio( "", 150, 36, 15, 15)
$OffSet3 = GUICtrlCreateRadio( "", 165, 36, 15, 15)
$OffSet4 = GUICtrlCreateRadio( "", 180, 36, 15, 15)
GUICtrlCreateLabel("-2  -1   0  +1 +2", 120, 50, 80, 15)
GUICtrlSetState($Offset2, $GUI_CHECKED)
;END CLOCK
GUISetState(@SW_SHOW)
#EndRegion ### 

Func _SyncCheck()
    If (($Check = 1) or ($Check = 4) or ($Check = 7)) and  $CStatus = 'On' and $CMode = '1' Then ;1, 4, 7
        Send("{q down}")
        Sleep(100)
        Send("{q up}")
        $CMode = '2'
    EndIf
    If (($Check = 2) or ($Check = 5) or ($Check = 8)) and  $CStatus = 'On' and $CMode = '2' Then;2, 5, 8
        Send("{w down}")
        Sleep(100)
        Send("{w up}")
        $CMode = '3'
    EndIf
    If (($Check = 3) or ($Check = 6) or ($Check = 9)) and  $CStatus = 'On' and $CMode = '3' Then;3, 6, 9
        Send("{e down}")
        Sleep(100)
        Send("{e up}")
        $CMode = '1'
    EndIf
EndFunc
Func _SyncChange()
    If _isPressed("25", $dll) Then
        GUICtrlSetData($OffSet, (GUICtrlRead($OffSet)-1))
        Sleep(200)
    ElseIf Not _isPressed("25", $dll) Then
    EndIf
    If _isPressed("27", $dll) Then
        GUICtrlSetData($OffSet, (GUICtrlRead($OffSet)+1))
        Sleep(200)
    ElseIf Not _isPressed("27", $dll) Then
    EndIf
EndFunc

While 1
    $nMsg = GUIGetMsg()
        If $nMsg = $GUI_EVENT_CLOSE Then
            Exit
        EndIf       
        If (_IsPressed('DD', $dll)) and $CStatus = 'Off' Then
            GUICtrlSetData($Sync, "  Checking Sync")
            GUICtrlSetBkColor($Sync, 0x006633)
            $CStatus = 'On'
            Sleep(200)
        EndIf
        If (_IsPressed('DD', $dll)) and $CStatus = 'On' Then
            GUICtrlSetData($Sync, "     Sync Time")
            GUICtrlSetBkColor($Sync, 0x000000)
            $CStatus = 'Off'
            Sleep(200)
        EndIf

        If $CStatus = 'On' Then
            _SyncCheck()
            _SyncChange()
        ElseIf $CStatus = 'Off' Then
            $CMode = '1'
        EndIf

;CLOCK STUFF
        If GUICtrlRead($Offset0) = $GUI_CHECKED Then
            $OffsetNum = '-2'
        EndIf
        If GUICtrlRead($Offset1) = $GUI_CHECKED Then
            $OffsetNum = '-1'
        EndIf
        If GUICtrlRead($Offset2) = $GUI_CHECKED Then
            $OffsetNum = '0'
        EndIf
        If GUICtrlRead($Offset3) = $GUI_CHECKED Then
            $OffsetNum = '+1'
        EndIf
        If GUICtrlRead($Offset4) = $GUI_CHECKED Then
            $OffsetNum = '+2'
        EndIf
        ;SLIDER
        $OffSetPos = '-1'
        $OffSetData = GUICtrlRead($OffSet)
        If $OffSetData <> $OffSetPos Then
            GUICtrlSetData($OffSetAmt, ($OffSetData*25) & "ms")
            $OffSetPos = (($OffSetData*25) & "ms")
        EndIf
        ;SLIDER END
        
        ;##OFFSET -2##
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-2)) and $OffsetNum = '-2' and ((@SEC) <> 01) and ((@SEC) < 12) Then;for seconds 0-59
            $Time1 = @HOUR & ":" & @MIN & ":0" & (@SEC-2)
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-2)) and $OffsetNum = '-2' and ((@SEC) > 11) Then;for seconds 10-58
            $Time1 = @HOUR & ":" & @MIN & ":" & (@SEC-2)
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-2)) and $OffsetNum = '-2' and ((@MIN) < 11) and ((@SEC) = 00) Then;for second 59 and minutes 1-9
            $Time1 = @HOUR & ":0" & (@MIN-1) & ":" & "58"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-2)) and $OffsetNum = '-2' and ((@MIN) > 10) and ((@SEC) = 00) Then;for second 59 and minutes 10-59
            $Time1 = @HOUR & ":" & (@MIN-1) & ":" & "58"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-2)) and $OffsetNum = '-2' and ((@MIN) < 11) and ((@SEC) = 01) Then;for second 59 and minutes 1-9
            $Time1 = @HOUR & ":0" & (@MIN-1) & ":" & "59"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-2)) and $OffsetNum = '-2' and ((@MIN) > 10) and ((@SEC) = 01) Then;for second 59 and minutes 10-59
            $Time1 = @HOUR & ":" & (@MIN-1) & ":" & "59"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        ;#OFFSET -2##
                
        ;##OFFSET -1##
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-1)) and $OffsetNum = '-1' and ((@SEC) <> 00) and ((@SEC) < 11) Then;for seconds 0-59
            $Time1 = @HOUR & ":" & @MIN & ":0" & (@SEC-1)
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-1)) and $OffsetNum = '-1' and ((@SEC) > 10) Then;for seconds 10-58
            $Time1 = @HOUR & ":" & @MIN & ":" & (@SEC-1)
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-1)) and $OffsetNum = '-1' and ((@MIN) < 10) and((@SEC) = 00) Then;for second 59 and minutes 1-9
            $Time1 = @HOUR & ":0" & (@MIN-1) & ":" & "59"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC-1)) and $OffsetNum = '-1' and ((@MIN) > 9) and((@SEC) = 00) Then;for second 59 and minutes 10-59
            $Time1 = @HOUR & ":" & (@MIN-1) & ":" & "59"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        ;#OFFSET -1##
        
        ;##OFFSET 0##
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & @SEC) and $OffsetNum = '0' Then
            $Time1 = @HOUR & ":" & @MIN & ":" & @SEC
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        ;##OFFSET 0##
        
        ;#OFFSET +1##
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+1)) and $OffsetNum = '+1' and ((@SEC) = 59) and ((@MIN) < 7) Then;for second 00
            $Time1 = @HOUR & ":0" & (@MIN+1) & ":" & "00"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+1)) and $OffsetNum = '+1' and ((@SEC) = 59) and ((@MIN) > 8) Then;for second 00
            $Time1 = @HOUR & ":" & (@MIN+1) & ":" & "00"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+1)) and $OffsetNum = '+1' and ((@SEC) < 9) Then;for seconds 1-9
            $Time1 = @HOUR & ":" & @MIN & ":0" & (@SEC+1)
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+1)) and $OffsetNum = '+1' and ((@SEC) > 8) and ((@SEC) < 59) Then;for seconds 10-59
            $Time1 = @HOUR & ":" & @MIN & ":" & (@SEC+1)
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        ;##OFFSET +1##
        
        ;#OFFSET +2##
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+2)) and $OffsetNum = '+2' and ((@SEC) = 59) and ((@MIN) < 10) Then;for second 0 and Min 0-10
            $Time1 = @HOUR & ":0" & (@MIN+1) & ":" & "01"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+2)) and $OffsetNum = '+2' and ((@SEC) = 59) and ((@MIN) > 9) Then;for second 01 and Min 10-58
            $Time1 = @HOUR & ":" & (@MIN+1) & ":" & "01"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+2)) and $OffsetNum = '+2' and ((@SEC) = 58) and ((@MIN) < 10) Then;for second 00 and Min 0-10
            $Time1 = @HOUR & ":0" & (@MIN+1) & ":" & "00"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+2)) and $OffsetNum = '+2' and ((@SEC) = 58) and ((@MIN) > 9) Then;for second 00 and Min 10-58
            $Time1 = @HOUR & ":" & (@MIN+1) & ":" & "00"
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+2)) and $OffsetNum = '+2' and ((@SEC) < 8) Then;for seconds 2-9
            $Time1 = @HOUR & ":" & @MIN & ":0" & (@SEC+2)
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        If ($Time1 <> @HOUR & ":" & @MIN & ":" & (@SEC+2)) and $OffsetNum = '+2' and ((@SEC) > 7) and ((@SEC) < 58) Then;for seconds 10-59
            $Time1 = @HOUR & ":" & @MIN & ":" & (@SEC+2)
            Sleep(GUICtrlRead($OffSet)*25)
            GUICtrlSetData($Time2, $Time1)
            $Hour = StringMid(GUICtrlRead($Time2), 1, 2)
            $Min = StringMid(GUICtrlRead($Time2), 4, 2)
            $Sec = StringMid(GUICtrlRead($Time2), 7, 2)
            $Check = StringMid(GUICtrlRead($Time2), 8, 1)
        EndIf
        ;##OFFSET +2##
        
        ;##SYNC FROM INTERNET
        If $nMsg = $Sync Then
        Run(@ComSpec & ' /c w32tm /resync')
        GUICtrlSetData($SetHour, $Hour)
        GUICtrlSetData($SetMin, $Min)
        GUICtrlSetData($SetSec, $Sec)
        EndIf
        ;##SYNC FROM INTERNET
        ;END CLOCK
WEnd

Sure, here it is. Last night I decided to just go with my code and added a slider that applies to a sleep time between the actual computer time and the display time, allowing a fine-tuned synchronization by 25ms increments. I also increased the possible offset amount to +-2 seconds, so technically our computer clocks can be as much as 5 seconds off (which is very unlikely) and still be synced within 25ms of each other(it could be even more exact but for my purposes 25ms is plenty).

The only bug in it is that at the top of the hour the time messes up for just one second.

After that one second has elapsed it goes back to working order. I can live with that, it isn't necessarily worth the extra time writing a code to compensate for one second. It doesn't affect synchronization for my purposes.

Thanks again.

Edited by Vicate
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...