This article mainly records the usual accumulation of things about NTP.
In order to connect to the NTP server, the device must be connected to the network, setting a different method, Conlio here.
There are many NTP servers, but some are not. The test is 202.120.2.101, which is the Network Center NTP server address of Shanghai Jiaotong University. The NTP client uses NtpClient, using the following methods:
$ ntpclient-s-t-i 10-h 202.120.2.101
First, NTP synchronization time test
Set a time at random:
$ date 09120013
Thu Sep 00:13:00 GMT-8 2013
Sync Time:
$ ntpclient-s-t-i 10-h 202.120.2.101
41526 58384.802 121782.0 24.6-2172899597099.9 37323.0 0
View time:
$ date
Sat Aug 20:38:07 GMT-8 2013
Write to the RTC
$hwclock-uw
In the test, the time zone is always wrong after the device is restarted, and a very good colleague who has left now tells me there is a place that is not set.
Modify/etc/default/rcs, open UTC, and set to Yes.
# set Utc=yes If your system clock is set to UTC (GMT), and utc=no if not.
Utc=yes
Note: The original is commented out.
After modification, synchronize time again:
$ ntpclient-s-t-i 10-h 202.120.2.101
41506 84272.529 61186.0 20.2 28896829196.1 28976.4 0
$ date
Fri Aug 15:26:10 GMT-8 2013
$ hwclock-uw
$ hwclock-r
Fri Aug 07:26:19 2013 0.000000 seconds
Time is no problem, clock chips are 8 hours less than the system.
Reboot device
Kernel Boot information:
setting system clock to 2013-08-23 07:26:32 UTC (1377242792)
View time after Login:
$ date
Fri Aug 15:26:46 GMT-8 2013
It's no problem this time.
Second, the time zone in the use of the program.
The time zone file for the Linux system is in the/usr/share/zoneinfo directory.
You can do a small test of the time zone.
$ date
Thu May 9 17:42:24 CST 2013
Copy time zone files
$ pwd
/usr/share/zoneinfo/asia
$ CP Tokyo/etc/localtime
$ date
Thu May 9 18:43:36 JST 2013
(Tokyo time is one hours faster than Beijing time)
Many host computer can make time zone choice, then, in the program how to respond to this choice.
You can consolidate each time zone file into an array, which refers to a single file in each time zone, such as East 8, where you can use any of the Shanghai, Chongqing, and Taipei of the Asia directory.
Arrays are shown below, of course, this array must be modified according to the actual situation.
Static char* timezone_files[] =
{
"Gmt+12",
"Gmt+11",
...
"GMT-12",
};
The host computer sends the time zone index value to the lower machine, by looking for the time zone file array, obtains the corresponding time zone file, then copies as/etc/localtime (soft link way also can). From the test above, the system time changes immediately when/etc/localtime changes. This completes the time zone setting.
PostScript: Computer time will not deceive, this article set up a variety of time and article writing time is very far away (test time is May early, with the end of August, now is the end of October), because these are gradually accumulated in the daily. From the time of the article and the passage of a certain sentence, you can learn that some things happened during this period, now changed, do not recall.
Late, written on October 20, 2013.