Jump to content

Check universal time


Recommended Posts

  • Moderators

trung0407,

I use this to get the local time:

#include <String.au3>
#include <INet.au3>

$iErrorCount = 0

While 1

    $iPing = Ping("www.uhrzeit.org")

    If @error Then
        TrayTip("Date Time Checker", "Connection Failed" & @CRLF & "Retrying in 5 secs", 5)
        Sleep(5000)
        $iErrorCount += 1
        If $iErrorCount > 10 Then
            TrayTip("Date Time Checker", "No Connection" & @CRLF & "Exiting....", 5)
            Sleep(5000)
            Exit
        EndIf
    Else
        TrayTip("Date Time Checker", "Connected" & @CRLF & "Reading date and time", 5)
        Sleep(2000)
        ExitLoop
    EndIf
WEnd

$sSource = _INetGetSource('http://www.uhrzeit.org/atomuhr.html')

$aTime = _StringBetween($sSource, '<div id="anzeige_zeit">', '</div>')
$aTime = StringSplit($aTime[0], ":")
$iSec = $aTime[3]
$iMin = $aTime[2]
$iHr  = $aTime[1] - 1
If $iHr = -1 Then $iHr = 23

$aDate = _StringBetween($sSource, '<div id="anzeige_datum">', '</div>')
$aDate = StringSplit($aDate[0], " ")

$sYear = $aDate[4]
$sDate = StringTrimRight($aDate[2], 1)
$iMonth = 0

Switch $aDate[3]
    Case "Januar"
        $iMonth = 1
    Case "Februar"
        $iMonth = 2
    Case "März"
        $iMonth = 3
    Case "April"
        $iMonth = 4
    Case "Mai"
        $iMonth = 5
    Case "Juni"
        $iMonth = 6
    Case "Juli"
        $iMonth = 7
    Case "August"
        $iMonth = 8
    Case "August"
        $iMonth = 9
    Case "Oktober"
        $iMonth = 10
    Case "November"
        $iMonth = 11
    Case "Dezember"
        $iMonth = 12
EndSwitch

TrayTip("Date Time Checker", "", 1)
MsgBox(0, "Now!", $iHr & ":" & $iMin & ":" & $iSec & @CRLF & $sDate & "/" & $iMonth & "/" & $sYear)

and _Date_Time_GetTimeZoneInformation to work out "The current bias for local time translation on this computer".

Seems to work quite well! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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