Because the local system is not accurate, it is decided to obtain the system from the Internet to correct the system.
ProgramDesign Procedure
1. Create a project;
2. Place a tedit control and a tclientsocket (on the Internet page) control on the form. Tedit is used to display the Greenwich Mean obtained after being converted to Beijing, and tclientsocket is used to obtain Greenwich mean from the Internet;
3. ProgramCode
Procedure tform1.formcreate (Sender: tobject );
Begin
Clientsocket1.host: = 'tick .usno.navy.mil '; // US Naval Observatory;
Clientsocket1.port: = 13;
Clientsocket1.open;
End;
Procedure tform1.clientsocket1read (Sender: tobject;
Socket: tcustomwinsocket );
VaR
Temptime: tdatetime;
HH, mm, SS, Ms: word;
Stime: string;
Begin
Stime: = socket. receivetext; // obtain Greenwich Mean;
Stime: = copy (stime,); // obtain the part;
Decodetime (strtotime (stime), HH, mm, SS, MS );
Hh: = (HH + 8) mod 24; // convert it to Beijing;
Temptime: = encodetime (HH, mm, SS, MS );
Edit1.text: = timetostr (temptime );
End;
4. Compile and run the program. wait a few seconds (depending on your network speed, wait for about one second). The tedit control displays the Beijing data converted from Greenwich.
How is it? It's easy. Give it a try! Note: Due to network latency
A program may get a few seconds of error, but unless you control the rocket launch, no
Then, this does not matter.
It is obtained from the US Naval Observatory. You can also obtain it from other sources. However, because each format is different, you should handle it when writing a program.
Domain Name Organization
Clock. SGI. comsgi
Tick.mit.edu MIT
Time. NIST. govnist