Get Standard Greenwich Time from Internet Time Server

zhaozj2021-02-11  199

Get Standard Greenwich Time from Internet Time Server

Since the system time is not accurate, it is determined that the system time is determined from the Internet Time Server to correct the system time. The programming steps are as follows: 1. New project; 2. Place a TEDIT control on the form and a TclientSocket (under the Internet page) control. TCLIENTSOCKET is used to display the GMCK to be used in Beijing time, and TclientSocket is used to get standard GMNet time from the Internet Time Server; = 'tick.usno.navy.mil'; // US Navy Observatory; ClientSocket1.Port: = 13; ClientSocket1.open;

procedure TForm1.ClientSocket1Read (Sender: TObject; Socket: TCustomWinSocket); var TempTime: TDateTime; hh, mm, ss, ms: word; sTime: string; begin sTime: = Socket.ReceiveText; // get GMT; sTime: = COPY (STIME, 12, 8); // Get the time part; decodetime (strtotime (stime), hh, mm, ss, ms); hh: = (hh 8) MOD 24; // transform into Beijing time; Temptime : = Encodetime (HH, MM, SS, MS); Edit1.Text: = Timetostr (Temptime); END; 4, compile operation, a little waiting for a few seconds (related to your network speed, the author waited for about a second The TEDIT control shows the Beijing time that is transformed from GMT.

how about it? Very simple. Try it! It is necessary to explain that this program has a few seconds of the time and standard time of this program, unless you are used to control the launch of rockets, which is not a matter. The author gets standard time from the US Navy Observatory, you can also get among other time servers, but because each time server has different time formats, you should pay attention to the corresponding processing when writing programs. Domain Organization CLOCK.SGI.com SGI Tick.mit.edu MIT Time.nist.gov NIST

转载请注明原文地址:https://www.9cbs.com/read-3744.html

New Post(0)