|
Thread: WSH
-
Nov 17th, 2000, 07:24 PM
#1
Thread Starter
New Member
WSH Get Time
Anyone know how to implement Karls example for getting the internet time using Windows Scripting Host and VBScript? (Or JScript?)
Thanks
[Edited by ShawnFx on 11-17-2000 at 07:30 PM]
-
Nov 21st, 2000, 12:13 PM
#2
Member
bring it to the top
I would love to know this also.
-
Nov 21st, 2000, 03:14 PM
#3
Hyperactive Member
Without creating a special control that can be referenced by the scripting host, you will have to find a website that will allow you to grab the information. The reason begin is that you cannot control the winsock dll through the scripting language, and IE (which you can control), will not report any data back if you try to access a site through port 13. Fortunately, the US Naval Observatory has an atomic clock that generates a static webpage when accessed. This allows use easily retrieve the information.
Code:
Const TIME_URL="http://tycho.usno.navy.mil/cgi-bin/timer.pl"
Dim UNC, LocalTime
UNC=GetTime(TIME_URL)
PacificTime=Left(UNC,Instr(UNC, ":")-1)
PacificTime=CInt(PacificTime) - 8 'Pacific time is 8 hours behind Universal Time
PacificTime=PacificTime & Mid(UNC, Instr(UNC, ":"))
if UNC<>"-1" then
msgbox "Universal time: " & UNC & vbcrlf & _
"Pacific Time: " & PacificTime,0, "Internet Time"
else
msgbox "Internet Time could not be resolved."
end if
Wscript.quit
Function GetTime(URL)
Dim ie
Dim Master_String
Dim str_substring
Dim str_index
Set ie=CreateObject("InternetExplorer.Application")
ie.navigate(URL)
Do while ie.busy=true
Wscript.sleep 500
Loop
Master_String=ie.document.body.innertext
if Instr(LCase(Master_String),"universal") <>0 then
str_index=Instr(LCase(Master_String), "universal")
str_substring=Left(Master_String, str_index -1)
str_index=InstrRev(str_substring, ",")
str_substring=Mid(str_substring, str_index + 1)
GetTime=str_substring
else
GetTime="-1"
end if
End Function
Unfortunately, I don't think that you can access the correct API to determine your system's Time Zone settings through the scripting host, so if you want to convert the universal time setting to local time, you will have to do something like the above.
Hope this is useful.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|