Войти

Показать полную графическую версию : [решено] Сверка времени через интернет


Centrinar
08-04-2011, 23:46
Интересен такой вопрос.
Как реализовать: скрипт сверяет время на ПК с эталоном временеи в интернете.
Спасибо

madmasles
09-04-2011, 00:57
Centrinar,
#include <INet.au3>

$sUrl = 'http://time.jp-net.ru/'
$sSource = _INetGetSource($sUrl)
If @error Or Not $sSource Then Exit
$sNow = StringRegExpReplace($sSource, '(?s).*?дата: (.*?)</h1>.*?время: (.*?)</h1>?.*', '\1 \2')
MsgBox(64, 'Info', 'Интернет: ' & $sNow & @CRLF & 'Компьютер:' & @YEAR & '-' & @MDAY & '-' & @MON & ' ' & _
@HOUR & ':' & @MIN & ':' & @SEC)

Creat0R
09-04-2011, 01:59
А зачем «_INetGetSource»? помоему эта функция уже не актуальна в AutoIt.

$sUrl = 'http://time.jp-net.ru/'

$sSource = InetRead (http://www.autoitscript.com/autoit3/docs/functions/InetRead.htm)($sUrl)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) $sSource Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
$sSource = BinaryToString (http://www.autoitscript.com/autoit3/docs/functions/BinaryToString.htm)($sSource)


$sNow = StringRegExpReplace (http://www.autoitscript.com/autoit3/docs/functions/StringRegExpReplace.htm)($sSource, '(?s).*(\d{4}-\d{2}-\d{2}).*(\d{2}:\d{2}:\d{2}).*', '\1 \2')
$sInfo = StringFormat (http://www.autoitscript.com/autoit3/docs/functions/StringFormat.htm)('Интернет: %s\nКомпьютер: %04i-%02i-%02i %02i:%02i:%02i', $sNow, @YEAR (http://www.autoitscript.com/autoit3/docs/macros.htm#@year), @MDAY (http://www.autoitscript.com/autoit3/docs/macros.htm#@mday), @MON (http://www.autoitscript.com/autoit3/docs/macros.htm#@mon), @HOUR (http://www.autoitscript.com/autoit3/docs/macros.htm#@hour), @MIN (http://www.autoitscript.com/autoit3/docs/macros.htm#@min) , @SEC (http://www.autoitscript.com/autoit3/docs/macros.htm#@sec))

MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(64, 'Info', $sInfo)

madmasles
09-04-2011, 02:22
А зачем «_INetGetSource»? »А я к ней привык. :)

PS
Ваш способ изящнее. :)




© OSzone.net 2001-2012