Jump to content

Time convertion help


 Share

Recommended Posts

This script gets the official time from the Internet, compares with your pc clock and updates if necessary. The problem is that it will only work for places where the time is GMT-3 (Like Buenos Aires). I was thinking of adding some combo to select the time zone so I can stick to the same website using some maths, but I can't do it :)

Can anyone give me a hand here? (I thought of using the date.au3 file, but it occurred to me after I finished, haha)

Here's my script: (sorry for the variables and functions in Spanish)

#include <Array.au3>
#include <Guiconstants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayMenuMode",1) 
Opt("TrayAutoPause",0)
Opt("TrayOnEventMode",1)

;Menu bandeja=================================
TrayCreateItem("About")
TrayItemSetOnEvent(-1, "about")
;=============================================

;ventana
GUICreate("Time UpDater",200,370)
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")

;Etiquetas=============================================
GUICtrlCreateLabel("PC time:",15,15)
$HoraSistema=GUICtrlCreateLabel(@HOUR&":"&@MIN&":"&@SEC,140,15)

GUICtrlCreateLabel("Internet Time:",15,30)
$HoraInternet=GUICtrlCreateLabel("",140,30,100)
    
GUICtrlCreateLabel("Hours:",15,60)
$MostrarHora=GUICtrlCreateLabel("",160,60,100)
$MostrarEstadoHora=GUICtrlCreateLabel("",15,75,175)

GUICtrlCreateLabel("Minutes:",15,105)
$MostrarMinutos=GUICtrlCreateLabel("",160,105,100)
$MostrarEstadoMinutos=GUICtrlCreateLabel("",15,120,175)

GUICtrlCreateLabel("Seconds:",15,150)
$MostrarSegundos=GUICtrlCreateLabel("",160,150,100)
$MostrarEstadoSegundos=GUICtrlCreateLabel("",15,165,175)

GUICtrlCreateLabel("      Pressing 'Refresh' repeatedly "&@CRLF&"         will cause bad-functioning",16,242)
GUICtrlSetColor(-1,0x00E84418)
;========================================================

;Botones
$Actualizar=GUICtrlCreateButton("",15,210,170)
GUICtrlSetOnEvent(-1,"Actualizar")
$Corregir=GUICtrlCreateButton("Update",15,320,170,-1)
GUICtrlSetOnEvent(-1,"Corregir")

;Grupos
GUICtrlCreateGroup("",7,1,186,50)
GUICtrlCreateGroup("",7,49,186,140)
GUICtrlCreateGroup("",7,187,186,100)
GUICtrlCreateGroup("Update system clock time",7,292,186,75)

GUISetState()
Actualizar()

;Funciones
Func Actualizar()
GUICtrlSetState($Actualizar,$GUI_DISABLE)
GUICtrlSetData($Actualizar,"Connecting...")

AdlibDisable();Deshabilita el refresco automático `para evitar desincronizacion.

$Hora_Actual=_Hora_actual()
$HoraAComparar=StringSplit($Hora_Actual,":")
;cambiar la info
GUICtrlSetData($MostrarHora,$HoraAComparar[1])
GUICtrlSetData($MostrarMinutos,$HoraAComparar[2])
GUICtrlSetData($MostrarSegundos,$HoraAComparar[3])
GUICtrlSetData($HoraInternet,$Hora_Actual)
GUICtrlSetData($HoraSistema,@HOUR&":"&@MIN&":"&@SEC)

$minX=@MIN
$segX=@SEC
$Check=StringLeft(@hour,1)
If $Check="0" Then
    $horaX=StringRight(@hour,1)
Else
    $horaX=@HOUR
EndIf

$DifHora=$HoraAComparar[1]-$horaX
$DifMin=$HoraAComparar[2]-$minX
$DifSeg=$HoraAComparar[3]-$segX

If $DifHora = 0 Then
    $HoraEstado="en hora"
Else
    If $DifHora > 0 Then
        $HoraEstado="atrasado"
    Else
        $HoraEstado="adelantado"
    EndIf   
EndIf

If $DifMin = 0 Then
    $MinEstado="en hora"
Else
    If $DifMin > 0 Then
        $MinEstado="atrasado"
    Else
        $MinEstado="adelantado"
    EndIf   
EndIf

If $DifSeg = 0 Then
    $SegEstado="en hora"
Else
    If $DifSeg > 0 Then
        $SegEstado="atrasado"
    Else
        $SegEstado="adelantado"
    EndIf   
EndIf

Select
Case $HoraEstado="en hora"
    GUICtrlSetData($MostrarEstadoHora,"Correct")
    GUICtrlSetColor($MostrarEstadoHora,0x0000FC00)
Case $HoraEstado="atrasado"
    GUICtrlSetData($MostrarEstadoHora,Abs($DifHora)&" hours slow")
    GUICtrlSetColor($MostrarEstadoHora,0x00E84418)
Case $HoraEstado="adelantado"
    GUICtrlSetData($MostrarEstadoHora,Abs($DifHora)&" hours fast")
    GUICtrlSetColor($MostrarEstadoHora,0x00E84418)
EndSelect

Select
Case $MinEstado="en hora"
    GUICtrlSetData($MostrarEstadoMinutos,"Correct")
    GUICtrlSetColor($MostrarEstadoMinutos,0x0000FC00)
Case $MinEstado="atrasado"
    GUICtrlSetData($MostrarEstadoMinutos,Abs($DifMin)&" minutes slow")
    GUICtrlSetColor($MostrarEstadoMinutos,0x00E84418)
Case $MinEstado="adelantado"
    GUICtrlSetData($MostrarEstadoMinutos,Abs($DifMin)&" minutes fast")
    GUICtrlSetColor($MostrarEstadoMinutos,0x00E84418)
EndSelect
    
Select
Case $SegEstado="en hora"
    GUICtrlSetData($MostrarEstadoSegundos,"Correct")
    GUICtrlSetColor($MostrarEstadoSegundos,0x0000FC00)
Case $SegEstado="atrasado"
    GUICtrlSetData($MostrarEstadoSegundos,Abs($DifSeg)&" seconds slow")
    GUICtrlSetColor($MostrarEstadoSegundos,0x00E84418)
Case $SegEstado="adelantado"
    GUICtrlSetData($MostrarEstadoSegundos,Abs($DifSeg)&" seconds fast")
    GUICtrlSetColor($MostrarEstadoSegundos,0x00E84418)
EndSelect
sleep(1200)
GUICtrlSetState($Actualizar,$GUI_ENABLE)
GUICtrlSetData($Actualizar,"Refresh")
AdlibEnable("Actualizar",10000); Permite el refresco automatico cada 10 seg.
EndFunc ;==>Actualizar()

Func _Hora_actual()
    Local $oHorax
    $oHTTP = ObjCreate("Microsoft.XMLHTTP")
    $oHTTP.Open("GET", "http://www.hidro.gov.ar/Hora/Hora.asp", False)
    $oHTTP.Send()
    $oHora = StringRegExp($oHTTP.ResponseText, "<h2 align='center'><font color='#0080C0'><font='Verdana'>(.*?)</font></h2>", 3)
    For $i = 0 To UBound($oHora) -1
        $oHorax = $oHorax & $oHora[$i]
    Next
    If $oHora <> "" Then
        Return $oHorax 
    Else
        SetError(1)
        Return -1
    EndIf
EndFunc;==>_Hora_actual()

Func corregir()
    If (GUICtrlRead($MostrarEstadoSegundos)<>"Correct") And (GUICtrlRead($MostrarEstadoHora)="Correct") And _
(GUICtrlRead($MostrarEstadoMinutos)="Correct") Then
        Dim $iMsgBoxAnswer
        $iMsgBoxAnswer = MsgBox(292,"Update Time","You are about to update the system clock for a difference of a few seconds." & @CRLF & "You might not notice it." & @CRLF & "" & @CRLF & "Continue anyway?")
        Select
        Case $iMsgBoxAnswer = 6 ;Yes
            GUICtrlSetState($Corregir,$GUI_DISABLE)
            GUICtrlSetData($Corregir,"Updating...")
            $HoraNueva =  _Hora_actual()
            Run(@ComSpec & " /c  time " & $HoraNueva, "", @SW_HIDE)
            MsgBox(64,"Time Updater","System clock updated successfully!")
            GUICtrlSetState($Corregir,$GUI_ENABLE)
            GUICtrlSetData($Corregir,"Update")
            Actualizar()
           Case $iMsgBoxAnswer = 7 ;No
        EndSelect
    Else
        GUICtrlSetState($Corregir,$GUI_DISABLE)
        GUICtrlSetData($Corregir,"Updating...")
        $HoraNueva =  _Hora_actual()
        Run(@ComSpec & " /c  time " & $HoraNueva, "", @SW_HIDE)
        MsgBox(64,"Time Updater","System clock updated successfully!")
        GUICtrlSetData($Corregir,"Update")
        GUICtrlSetState($Corregir,$GUI_ENABLE)
        Actualizar()
    EndIf
EndFunc

Func _exit()
    Exit
EndFunc

Func about()
    MsgBox(0,"About Time Updater","WebSite to get time: http://www.hidro.gov.ar/Hora/Hora.asp")
EndFunc



While 1
    Sleep(10)
WEnd
Edited by Nahuel
Link to comment
Share on other sites

:)

Maby post from theguy0000 can help

Look heare

youl get the time zone, and with that i think that you can (with some hard work, and with alot of strange variables ^^) reform your time + 3 +- GTM = time on your time zone

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
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...