Sign in to follow this  
Followers 0
datkewlguy

retreive real time?

17 posts in this topic

Hello, just wondering if anyone knew of any good ways to return the actual date, instead of the one on your computer.

Share this post


Link to post
Share on other sites



Well that is okay, but i really need to return this info and have it used in a script and that is where i am stuck

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I been looking for a cmd line utility to return a time, but haven't had much luck. I was thinking along the lines of:

net time \\time.nist.gov

But that doesn't work.

Edited by steveR

AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.

Share this post


Link to post
Share on other sites

hmm, i cant get it to work either, the params are this though if anyone else can figure it out...

==================================

NET TIME

\\computername | /DOMAIN[:domainname] | /RTSDOMAIN[:domainname]] [/sET]

[\\computername] /QUERYSNTP

[\\computername] /SETSNTP[:ntp server list]

==================================

If anyone can figure this out for me it'd be very useful

Share this post


Link to post
Share on other sites

Even though the docs for NET TIME say it should do the trick, it doesn't. Not sure why. This does work though:

Create W32Time.ini in the @WINDOWS folder that contains the following:

[W32Time]Type=NTP

Log=yes

Period=0

TASync=no

NTPServer=pool.ntp.org

LocalNTP=no

Then start (or restart) the "Windows Time" service... watch your time change.

If you need command line...

NET START W32Time

For the gory details, see W32Time Network Time Service (from MS)

And a list of regional Public NTP Servers

/disclaimer, works for me under Win2000, mileage may vary on other platforms.


601DisengageEnd Program

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Will this redirect to stdout? That's what we are looking for. A string or integer or something returned that can be parsed to be used in a script.

Here is an excerpt from the protocol. If we could get a hold of the UTC number.

Network Time Protocol (RFC-1305)
The Network Time Protocol (NTP) is the most commonly used Internet time protocol, and the one that provides the best performance. Large computers and workstations often include NTP software with their operating systems. The client software runs continuously as a background task that periodically gets updates from one or more servers. The client software ignores responses from servers that appear to be sending the wrong time, and averages the results from those that appear to be correct.

Many of the available NTP software clients for personal computers dont do any averaging at all. Instead, they make a single timing request to a signal server (just like a Daytime or Time client) and then use this information to set their computers clock. The proper name for this type of client is SNTP (Simple Network Time Protocol).

The NIST servers listen for a NTP request on port 123, and respond by sending a udp/ip data packet in the NTP format. The data packet includes a 64-bit timestamp containing the time in UTC seconds since January 1, 1900 with a resolution of 200 ps.
Edited by steveR

AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

dos command, time /t

EDIT: ah, I see the the object was to Determine the correct time, not to Correct the time... so sorry.

EDIT2:

Ok, here's the low-down:

w32tm -once -test

It produces a crap-load of output but does give the info you want w/o changing the local clock. (-once for only query the server once, and -test for don't set my clock) It appears that you can't choose the server from command line however. I turned off my time service, renamed the W32Time.ini file, AND rebooted, but it had saved the time server in the registry under HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\W32Time\Parameters ntpserver

I hope that helps :D

EDIT3:

And guess what! NET TIME /setsntp:xxxx changes that registry entry if you don't want to go monkeying around with finding the correct entry to change. :)

EDIT4:

The line that is consistently there no matter how far the clock is off is the one that says "ClockError", value is in ms

Edited by Smed

601DisengageEnd Program

Share this post


Link to post
Share on other sites

Well i still can't figure things out, What im working on is an expiration program and having it not work after a certain date... but it is weak if it can be removed simply by changing your date. I just need to aquire a date from the internet and have the script recognize that as the date, or correct the date to that.

Share this post


Link to post
Share on other sites

I take it no one knows... I've gotten pretty close but the best i can do is return the time from a networked computer...

Share this post


Link to post
Share on other sites

Glad you figured something out. Unfortunatly, those switches aren't supported on xp/nt.  :)

<{POST_SNAPBACK}>

works great under W2K, try adding the -v option if you're getting no output. haven't tested with XP yet.

601DisengageEnd Program

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

*Might* work. More than likely contains bugs

$tempFile = "temp.txt"
InetGet("http://www.whattimeisit.com/", $tempFile, 1)
$text = FileRead($tempFile, FileGetSize($tempFile))

$start = StringInStr($text, "<B>")
$stop = StringInStr($text, "</B>")

$text = StringMid($text, $start+3, $stop-$start-3)
$text = StringReplace($text, "<BR>", "")
$text = StringSplit($text, @LF)

$date = StringStripWS($text[1], 3);date in the form Month, D YYYY
$time = StringStripWS($text[2], 3);time in the form hh:mm:ss PM

If StringInStr($time, "PM") Then $time = Number($time) + 12 & ":" & StringTrimRight($time, 3)
$time = StringTrimRight($time, 3)

$start = StringInStr($date, ",")
$stop = StringInStr($date, " ", 1, -1)

$month = StringLeft($date, $start-1)
$day = StringMid($date, $start+2, $stop-$start-2)
If StringLen($day) = 1 Then $day = "0" & $day
$year = StringMid($date, $stop+1)
$month = StringInStr("       January   February  March   April   May       June   July    August    September October   November  December", $month)/10

MsgBox(4096,"", $year & "/" & $month & "/" & $day & " " & $time)

; Optionally delete the file:
;FileDelete($tempFile)
Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

actually that was about perfect, i made some tiny changes barely noticable though, now my result is in the wrong timezone too fast, how can i make this read the US Eastern Time?

$tempFile = "temp.txt"
InetGet("http://www.whattimeisit.com/", $tempFile, 1)
$text = FileRead($tempFile, FileGetSize($tempFile))

$start = StringInStr($text, "<B>")
$stop = StringInStr($text, "</B>")

$text = StringMid($text, $start+3, $stop-$start-3)
$text = StringReplace($text, "<BR>", "")
$text = StringSplit($text, @LF)

$date = StringStripWS($text[1], 3);date in the form Month, D YYYY
$time = StringStripWS($text[2], 3);time in the form hh:mm:ss PM

If StringInStr($time, "PM") Then $time = Number($time) + 12 & ":" & StringTrimRight($time, 3)
$time = StringTrimRight($time, 3)

$start = StringInStr($date, ",")
$stop = StringInStr($date, " ", 1, -1)

$month = StringLeft($date, $start-1)
$day = StringMid($date, $start+2, $stop-$start-2)
If StringLen($day) = 1 Then $day = "0" & $day
$year = StringMid($date, $stop+1)
$month = StringInStr("       January   February  March   April   May       June   July    August    September October   November  December", $month)/10

; Optionally delete the file:
FileDelete($tempFile)

MsgBox(4096,"", $month & "/" & $day & "/" & $year & " ");& $time

Share this post


Link to post
Share on other sites

k thanks again :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0