Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


How to Get GM Time from Time Servers

Keywords:  greenwich mean time GMT universal coordinated time UTC   

I was playing with the Internet Extender and created some code for getting the GM Time from an Internet Time Server. Here is a copy of it. At the bottom is a list of Time Servers but I can't guarantee that the list is accurate, I just copied it from a Windows Help file.
:GetGmTime
:RequestTime


;Tell the System that we will need the Internet Library
AddExtender("wwwsk34I.dll")

;How many seconds do we wait before asking again?
WaitForTime=15

;See bottom of this file for a list of Time Servers
TimeServer="tock.usno.navy.mil"
TimePort=37

;Request for Central Standard Time and a Synchronized base time.
;Get the Ip Address for this machine by 
;opening and connecting a socket to a known Server who support "daytime".
talksocket=sOpen()

;This line of Code can take upto 1 minute to complete if the server does not respond?
ret=sConnect(talksocket,"%TimeServer%","%TimePort%")
;Even if the last line times out there is no error?
err=wxGetLastErr()

LoopCnt=1
Status=@FALSE
While LoopCnt
If (sOk2Recv(talksocket,1)==@FALSE) 
  sClose(talksocket)
  GoTo RequestTime
EndIf

binbuf = BinaryAlloc(1000)
BinaryEODSet(binbuf,1000)
binaddr=IntControl(42,binbuf,0,0,0)
Status=sRecvBinary(talksocket, binaddr, 4)

If (Status==@FALSE)
  sClose(talksocket)
  GoTo RequestTime
EndIf


;Number of Seconds since 1900 Jan 01 00:00:00
;If return is B6F39734 then byte4=B6 byte3=F3 byte2=97 byte1=34
byte4=BinaryPeek( binbuf, 0 )
byte3=BinaryPeek( binbuf, 1 )
byte2=BinaryPeek( binbuf, 2 )
byte1=BinaryPeek( binbuf, 3 )

;Number of Seconds since 1900 Jan 01 00:00:00
;For example return of B6F39734 Word2=B6F3 Word1=9734
Word1=byte1+(256*byte2)
Word2=byte3+(256*byte4)

;Add in Word1 Seconds
GmTime=TimeAdd("1900:01:01:00:00:00","0000:00:00:00:00:%Word1%")

;Add in Word2 Seconds by chunks because it is 
;too big for for a double word value(>0x7FFF FFFF or 2147483647).
While Word2>0
  If Word2>30000
    GmTime=TimeAdd("%GmTime%","0000:00:00:00:00:1966080000")
    Word2=Word2-30000
  Else
    Remainder=Word2*65536
    GmTime=TimeAdd("%GmTime%","0000:00:00:00:00:%Remainder%")
    Word2=Word2-Word2
  EndIf
EndWhile

;All done with this Socket
sClose(talksocket)

Return
List Compiled by Argun Tekant, Locutus Codeware

Public NTP Secondary (stratum 2) Time Servers

;Time Server Name	Location

Authored by Argun Tekant, Locutus Codeware
;ashe.cs.tcd.ie		Trinity College, Dublin, Ireland 
;augean.eleceng.adelaide.edu.au		University of Adelaide, South Australia 
;bernina.ethz.ch	Swiss Fed. Inst. of Technology, CH 8092 Zurich, Switzerland 
;black-ice.cc.vt.edu	Virginia Tech Computing Center, Blacksburg, VA, USA 
;chime1.surfnet.nl	SURFnet bv, Utrecht, The Netherlands 
;clepsydra.dec.com	DEC Western Research Laboratory, Palo Alto, CA 
;clock.psu.edu		Penn State University, University Park, PA 
;clock.tricity.wsu.edu		Washington State University Tri-Cities, Richland, Wa 
;delphi.cs.ucla.edu	UCLA Computer Science Department, Los Angeles, CA 
;esavax.esa.lanl.gov		Los Alamos National Laboratory - Los Alamos, NM 
;fartein.ifi.uio.no	University of Oslo, Norway 
;fuzz.psc.edu		PSC Supercomputer Center, Pittsburgh, PA 
;gazette.bcm.tmc.edu		Baylor College of Medicine, Houston, Tx 
;heechee.esa.lanl.gov		Los Alamos National Laboratory, Los Alamos, NM 
;lib1.tcd.ie	Trinity College, Dublin, Ireland 
;libra.rice.edu		Rice University, Houston, TX 
;louie.udel.edu		University of Delaware, Newark, DE 
;nic.near.net		Cambridge, MA 
;noc.near.net		Cambridge, MA 
;ntp.css.gov	Center for Seismic Studies, Arlington, VA 
;ntp.univ-lyon1.fr	CISM, Lyon, France 
;ntp0.strath.ac.uk	Strathclyde University, Glasgow, Scotland. 
;ntp0.cornell.edu	Cornell University, Ithaca, NY 
;ntp.adelaide.edu.au		University of Adelaide, South Australia 
;ntp-0.cso.uiuc.edu	University of Illinois, Champaign, IL 
;ntp-1.cso.uiuc.edu	University of Illinois, Champaign, IL 
;ntp-2.cso.uiuc.edu	University of Illinois, Champaign, IL 
;salmon.maths.tcd.ie	Trinity College, Dublin, Ireland 
;sundial.columbia.edu		Morningside Campus, Columbia University, New York, NY 
;tick.cs.unlv.edu	UNLV Computer Science Department, Las Vegas, NV 
;timeserver.cs.umb.edu		University of Massachusetts, Boston, MA 
;tmc.edu	Baylor College of Medicine, Houston, Tx 
;tock.cs.unlv.edu	UNLV Computer Science Department, Las Vegas, NV 
;vtserf.cc.vt.edu	Virginia Tech Computing Center, Blacksburg, VA, USA 
;wuarchive.wustl.edu	Washington University, St. Louis, Missouri, USA 
;yoyo.aarnet.edu.au	The University of Adelaide, Adelaide, South AUSTRALIA 

;Public NTP Primary (stratum 1) Time Servers 

;Time Server Name	Location

;apple.com	Apple Computer, Cupertino, CA 
;bitsy.mit.edu		MIT Information Systems, Cambridge, MA 
;clock.isc.org		Internet Software Consortium, Palo Alto, CA 
;clock.llnl.gov		Lawrence Livermore National Laboratory, Livermore, CA 
;clock.nc.fukuoka-u.ac.jp	Fukuoka university, Fukuoka, Japan 
;clock.tl.fukuoka-u.ac.jp	Fukuoka university, Fukuoka, Japan 
;lerc-dns.lerc.nasa.gov		 NASA Lewis Research Center, Cleveland, OH 
;ncar.ucar.edu		 NCAR Supercomputer Center, Boulder, CO 
;norad.arc.nasa.gov	NASA Ames Research Center, Moffett Field, CA 
;ntp.syd.dms.csiro.au		National Measurements Laboratory, Sydney Australia. 
;ntp0.nl.net	NLnet, Amsterdam, The Netherlands 
;ntps1-0.uni-erlangen.de	University Erlangen-Nuernberg, D-91058 Erlangen, FRG 
;ntps1-0.cs.tu-berlin.de	Technische Universitaet Berlin, D-10587 Berlin, FRG 
;ntps1-1.cs.tu-berlin.de	Technische Universitaet Berlin, D-10587 Berlin, FRG 
;ntps1-1.uni-erlangen.de	University Erlangen-Nuernberg, D-91058 Erlangen, FRG 
;ntps1-2.uni-erlangen.de	University Erlangen-Nuernberg, D-91058 Erlangen, FRG 
;otc1.psu.edu		Penn State University, University Park, PA 
;ntp.cc.utexas.edu	University of Texas at Austin, Austin TX 
;tick.usno.navy.mil	U.S. Naval Observatory, Washington, DC 
;Time1.Stupi.SE		Stupi AB, Stockholm, SWEDEN 
;timer.unik.no		UNIK (University Department at Kjeller), Kjeller, Norway 
;tock.usno.navy.mil	U.S. Naval Observatory, Washington, DC 
;wwvb.erg.sri.com	SRI International, Menlo Park, CA 
;wwvb.isi.edu		USC Information Sciences Institute, Marina del Rey, CA 

Article ID:   W12608
Filename:   How to Get GM Time from Time Servers.txt