Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QM DATE conversion
#9
That version sets computer time. This version just returns time.

Function GetInternetTime_tycho_usno_navy_mil
Code:
Copy      Help
;/
function! DateTime&t

;Gets current UTC time from http://tycho.usno.navy.mil/timer.html.
;Returns 1 if successful. Returns 0 if fails to connect. Error if web page removed or modified.

;REMARKS
;The web page does not contain year and milliseconds. For year this function uses the computer's clock.

;EXAMPLE
;DateTime t
;if(!GetInternetTime_tycho_usno_navy_mil(t)) out "failed"; ret
;t.UtcToLocal
;out t.ToStr(4)


if(!IntPing("http://tycho.usno.navy.mil")) ret
;download file
Http h; str s
if(!h.GetUrl("http://tycho.usno.navy.mil/timer.html" &s)) ret
;get time string
ARRAY(str) a
if(findrx(s "(\w{3})\. (\d\d), (\d\d):(\d\d):(\d\d)" 0 2 a)<0) end "changed web page"
;get current time (year is missing in web file)
SYSTEMTIME st; GetSystemTime &st
;fill structure
lpstr m="JanFebMarAprMayJunJulAugSepOctNovDec"
int i=find(m a[1]); if(i<0) end "changed web page"
st.wMonth=i/3+1
st.wDay=val(a[2])
st.wHour=val(a[3])
st.wMinute=val(a[4])
st.wSecond=val(a[5])
st.wMilliseconds=999

t.FromSYSTEMTIME(st)
ret 1


Messages In This Thread

Forum Jump:


Users browsing this thread: 11 Guest(s)