rudi
New Member
Posts: 4
|
Post by rudi on Dec 28, 2022 10:55:44 GMT
I need for an external device to send the UTC time via my Windows10 PC.
The following commands i use:
100 Rem TZUTIL IS COMMAND TO CHANGE TIMEZONE | UTC = UTC TIME SET
110 KOMMANDO$ = "TZUTIL /S " + Chr$(34) + "UTC" + Chr$(34)
120 Shell _Hide KOMMANDO$
Yes, i do still use line numbers..... But thats not the problem.
When after these commands, i ask via PRINT TIME$, i do not get the time as it must be. (actually, there is no change at all) I live in the Netherlands, so thats now a time difference of 1 hour.
BUT, When i open a cmd-box and do TZUTIL /S "UTC" the time is changed to UTC.
What or where do i make a mistake?
|
|
tonylazuto
New Member
Tony Lazuto says hello
Posts: 25
|
Post by tonylazuto on Dec 28, 2022 19:26:30 GMT
try cmd /c before the tzutil
|
|
rudi
New Member
Posts: 4
|
Post by rudi on Dec 28, 2022 21:55:04 GMT
I do not know how to implement the "cmd /c" in my program.
But i think i found a solution.
I use a new batch file. Inside this batch file is:
@echo OFF CALL UTC.BAT >NUL CALL GMT-TIME64.EXE CALL LT.BAT >NUL @echo ON
Line 2 starts the batch file that makes the pc clock running with the utc timezone. Line 3 starts my communication program to set the utc time in my Trakbox (for controlling antennes pointed to satellites) Line 4 starts the batch file that makes the pc clock go back to local timezone.
It is not a beauty solution, but it is working. (I get an extra black screen. Maybe because i open a batch file inside a batch file.)
|
|
tonylazuto
New Member
Tony Lazuto says hello
Posts: 25
|
Post by tonylazuto on Dec 30, 2022 16:38:33 GMT
What I meant is that in your call to tzutil, just put "cmd /c" before it. KOMMANDO$ = "cmd /c TZUTIL /S " + Chr$(34) + "UTC" + Chr$(34)
|
|
rudi
New Member
Posts: 4
|
Post by rudi on Dec 30, 2022 17:31:26 GMT
I just did that and it has no effect. You can see it in the next example:
10 Cls 20 Locate 10, 16: Print Time$; 30 A$ = "CMD /C TZUTIL /S " + Chr$(34) + "W. Europe Standard Time" + Chr$(34) 40 Locate 10, 27: Print "* ";: Print A$; 50 Shell _Hide A$ 60 _Delay (2) 70 Locate 10, 27: Print " "; 80 Locate 11, 16: Print Time$; 90 A$ = "CMD /C TZUTIL /S " + Chr$(34) + "UTC" + Chr$(34) 100 Locate 11, 27: Print "* ";: Print A$; 110 Shell _Hide A$ 120 _Delay (2) 130 Locate 11, 27: Print " ";: GoTo 20
Right under in the screen, i see the clock is changing every 2 second. As it should be. But the program prints every 2 seconds the time on the screen, but that time is not changing. And that is the problem.
I hope you have another solution.
Still thank you for trying to help.
|
|
tonylazuto
New Member
Tony Lazuto says hello
Posts: 25
|
Post by tonylazuto on Dec 30, 2022 19:26:59 GMT
I'm not sure how comfortable you are with using Win32 API in QB64 but this could be of some assistance: SetTimeZoneInformation
|
|
|
Post by mdijkens on Dec 31, 2022 10:25:45 GMT
Why not use GetSystemTime to retrieve UTC and send that to external device in the format required:
Declare Dynamic Library "Kernel32" Sub GetUTC Alias GetSystemTime (lpSystemTime As String) End Declare
t$ = Space$(16): GetUTC t$ For i% = 1 To 15 Step 2 Print CVI(Mid$(t$, i%, 2)); 'prints UTC year,month,weekday,day,hour,minute,second,millis Next i%
or with a structure:
Type SYSTIME year As Integer month As Integer weekday As Integer day As Integer hour As Integer minute As Integer second As Integer millis As Integer End Type Declare Dynamic Library "Kernel32" Sub GetUTC Alias GetSystemTime (lpSystemTime As SYSTIME) End Declare
Dim st As SYSTIME: GetUTC st Print st.year, st.month, st.day, st.weekday Print st.hour, st.minute, st.second, st.millis
I think it is bad practice to change system clock in your program
|
|
rudi
New Member
Posts: 4
|
Post by rudi on Jan 1, 2023 23:33:49 GMT
Dear mdijkens,
Thanks very much for your routines.
The second one was easier for me to understand, but the first one was the best to implement in my program.
And yes, you are completely right. I did some dirty programming. But with my experience out of the very deep past,
i was not unhappy to succeed a little bit and completely on my way my goal. Your solution is much better and is already working in my system.
Thanks again.
Rudi.
|
|