Jump to content

Function _SetDate & _SetTime


arryo
 Share

Recommended Posts

Hello,

I have a script which should sync the PC's time to a time of a website.

Here is the code:

#include <INet.au3>
#Include <String.au3>
#Include <Date.au3>
#Include <Array.au3>

Local $Source

Local $year
Local $month
Local $day
Local $hour
Local $minute
Local $second

Global $string1
Global $string2
Local $string

Global $shit

Global $mothafuck






ToolTip("Fix: Connecting to http://www.uhrzeit.org/atomuhr.html...",0,0)


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




ToolTip("Fix: Connected! Reading time...",0,0)


$string1 = _StringBetween($Source, 'anzeige_zeit">','</div>')
$string2 = _StringBetween($Source, 'anzeige_datum">','</div>')



; GET TIME.

$string = $string1[0]

$shit = StringSplit($string, ":")


; --> get hour, minute, second

$hour = $shit[1]
$minute = $shit[2]
$second = $shit[3]




; GET DATE.

$string = $string2[0]



; --> get month



If StringRegExp($string, "Januar") = 1 Then
    $month = 1
elseIf StringRegExp($string, "Februar") = 1 Then
    $month = 2
elseIf StringRegExp($string, "März") = 1 Then
    $month = 3
elseIf StringRegExp($string, "April") = 1 Then
    $month = 4
elseIf StringRegExp($string, "Mai") = 1 Then
    $month = 5
elseIf StringRegExp($string, "Juni") = 1 Then
    $month = 6
elseIf StringRegExp($string, "Juli") = 1 Then
    $month = 7
elseIf StringRegExp($string, "August") = 1 Then
    $month = 8
elseIf StringRegExp($string, "September") = 1 Then
    $month = 9
elseIf StringRegExp($string, "Oktober") = 1 Then
    $month = 10
elseIf StringRegExp($string, "November") = 1 Then
    $month = 11
elseIf StringRegExp($string, "Dezember") = 1 Then
    $month = 12
Else
MsgBox(1, "Error", "DATE ERROR! CONTACT THE ADMINISTRATOR: MANUEL!")
Endif


; --> get year

$year = StringRight($string, 4)
    
    
; --> get day
    
$mothafuck = _StringBetween($string, '  ','. ')

$day = $mothafuck[0]


; YAY FINISHED.


ClipPut($string)




ToolTip("Fix: Setting Time...",0,0)



; FIX THE SHIT...
StringFormat('i', $day,$month,$year,$hour,$minute,$second)

If StringLen($day) = 1 Then
    $day = 0&$day
Endif


If StringLen($month) = 1 Then
    $month = 0&$month
Endif

If StringLen($hour) = 1 Then
    $hour = 0&$hour
Endif


If StringLen($minute) = 1 Then
    $minute = 0&$minute
Endif

If StringLen($second) = 1 Then
    $second = 0&$second
Endif



ConsoleWrite($day)
ConsoleWrite(@CRLF)
ConsoleWrite($month)
ConsoleWrite(@CRLF)
ConsoleWrite($year)
ConsoleWrite(@CRLF)
ConsoleWrite($hour)
ConsoleWrite(@CRLF)
ConsoleWrite($minute)
ConsoleWrite(@CRLF)
ConsoleWrite($second)
ConsoleWrite(@CRLF)




_SetDate($day,$month,$year)
_SetTime($hour,$minute,$second)

;_SetDate(20,10,2004)

My problem: The format of the _SetDate & _SetTime. Whats the correct format?

Another problem:

Even the example from the AutoIt Help doesnt work!

_SetDate(20,10,2004) ; Set the current date to 20-10-2004

_SetTime(20,15,30) ; Set time to 20:15:30

The Error I get:

C:\Programme\AutoIt3\Include\Date.au3 (1341) : ==> Subscript used with non-Array variable.:

Return Int($iRetval[0])

Return Int($iRetval^ ERROR

Link to comment
Share on other sites

What version are you running? That line 1341 in the current Date.au3 has no array reference in it:

Return Int($iRetval)

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

PsaltyDS,

I think this bug was fixed here.

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

That's why I asked about the version arryo was running (Trac #1378):

Fixed by revision [5520] in version: 3.3.3.2

That's before even the current Prod version, let alone current Beta.

:D

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thank you!

Works fine now.

I can share the program for you (The BIOS Battery of my PC is broken):

(This program sets the time to the current EUROPE time):

#include <INet.au3>
#Include <String.au3>
#Include <Date.au3>
#Include <Array.au3>

Local $Source

Local $year
Local $month
Local $day
Local $hour
Local $minute
Local $second

Global $string1
Global $string2
Local $string

Global $shit

Global $mothafuck


Local $check

Sleep(10000)




$x = 0

Do
$x = $x + 1

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

if $check = True Then
ToolTip("Time Fix: Connected! Reading time...",0,0)
$x = 100
Else



$y = 0
Do 
ToolTip("Fix: Connection Error. Retry in " & 10 - $y & " seconds. Try Nr.: "&$x,0,0)
$y = $y + 1
Sleep(1000)
Until $y = 10


Endif

Until $x = 10 OR $x = 100

if $x = 10 Then
MsgBox(1, "Time Fix", "No Internet connection. Could not set date correct.")
Exit
Endif


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




ToolTip("Time Fix: Connected! Reading time...",0,0)


$string1 = _StringBetween($Source, 'anzeige_zeit">','</div>')
$string2 = _StringBetween($Source, 'anzeige_datum">','</div>')



; GET TIME.

$string = $string1[0]

$shit = StringSplit($string, ":")


; --> get hour, minute, second

$hour = $shit[1]
$minute = $shit[2]
$second = $shit[3]




; GET DATE.

$string = $string2[0]



; --> get month



If StringRegExp($string, "Januar") = 1 Then
    $month = 1
elseIf StringRegExp($string, "Februar") = 1 Then
    $month = 2
elseIf StringRegExp($string, "März") = 1 Then
    $month = 3
elseIf StringRegExp($string, "April") = 1 Then
    $month = 4
elseIf StringRegExp($string, "Mai") = 1 Then
    $month = 5
elseIf StringRegExp($string, "Juni") = 1 Then
    $month = 6
elseIf StringRegExp($string, "Juli") = 1 Then
    $month = 7
elseIf StringRegExp($string, "August") = 1 Then
    $month = 8
elseIf StringRegExp($string, "September") = 1 Then
    $month = 9
elseIf StringRegExp($string, "Oktober") = 1 Then
    $month = 10
elseIf StringRegExp($string, "November") = 1 Then
    $month = 11
elseIf StringRegExp($string, "Dezember") = 1 Then
    $month = 12
Else
MsgBox(1, "Time Fix", "DATE ERROR! CONTACT THE ADMINISTRATOR")
Endif


; --> get year

$year = StringRight($string, 4)
    
    
; --> get day
    
$mothafuck = _StringBetween($string, ', ','. ')



$day = $mothafuck[0]


; YAY FINISHED.


ClipPut($string)




ToolTip("Time Fix: Setting Time...",0,0)



; FIX THE SHIT...
StringFormat('i', $day,$month,$year,$hour,$minute,$second)

If StringLen($day) = 1 Then
    $day = 0&$day
Endif


If StringLen($month) = 1 Then
    $month = 0&$month
Endif

If StringLen($hour) = 1 Then
    $hour = 0&$hour
Endif


If StringLen($minute) = 1 Then
    $minute = 0&$minute
Endif

If StringLen($second) = 1 Then
    $second = 0&$second
Endif



_SetDate($day,$month,$year)
_SetTime($hour,$minute,$second)

ToolTip("Time Fix: Success! Set date to " & $day & "." & $month & "." & $year & ", " & $hour & ":" & $minute & ":" & $second & ".",0,0)


Sleep(5000)

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