Set the time zone in Linux

Source: Internet
Author: User

 

Time and time zone settings
First, check whether UTC or local time is used.
UTC (Universal Time Coordinated) = GMT (Greenwich Mean Time)
Local time is the time on your watch

Traditional POSIX computers (Solaris, BSD, UNIX) use the UTC format
Linux can process UTC time and local time used by poor windows

Whether the UTC or local time is used can be determined as follows:
If both Linux and Windows are installed on the machine, we recommend that you use local time
If only Linux is installed on the machine, we recommend that you use UTC
After confirming, edit/etc/sysconfig/clock. UTC = 0 is local time; UTC = 1 is UTC (GMT)

1) Use CAT/etc/sysconfig/clock to view the current time zone
linux5 :~ # Cat/etc/sysconfig/clock
# path: System/environment/clock
# Description: information about your timezone and time
# type: string
# servicerestart: boot. clock
# set to "-U" if your system clock is set to UTC, and to "-- localtime"
# If your clock runs that way.
#
hwclock = "-U"

# Type: string (Europe/Berlin, Europe/London, Europe/Paris)
# Servicerestart: boot. Clock
#
# Timezone (e.g. CET)
# (This will set/usr/lib/zoneinfo/localtime)
#
Timezone = "US/Pacific"
Default_timezone = "US/Pacific"
Linux5 :~ #

2) use tzselect to set the time zone. The final result is as follows:

You can make this change permanent for yourself by appending the line
TZ = 'Asia/Shanghai'; export TZ
To the file '. profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
Can use the/usr/bin/tzselect command in shell scripts:
Asia/Shanghai
Linux5 :~ #

3) copy the corresponding time zone file and replace the System Default Time Zone
Linux5 :~ # Cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
Linux5 :~ #

4) write the current time to the BIOS for permanent effect (to prevent failure after restart)
Linux5 :~ # Hwclock
Tue Jan 29 18:22:59 2008-0.565688 seconds
Linux5 :~ #

10. Configure the NTP client
Edit/etc/NTP. conf and add a line of server 10.30.1.10. 10.30.1.105 is the clock server, as shown below:
Linux:/var/log # grep-V \ #/etc/NTP. conf

Server 10.30.1.105

View the NTP service status
Linux:/var/log #/etc/init. d/xntpd status
Checking for Network Time Protocol daemon (ntpd): unused

Set the time zone and time
/Usr/sbin/zic-l PRC
/Bin/date "+ % H: % m: % s-% d-% m-% Y"

Write back hardware clock
/Sbin/hwclock -- hctosys -- localtime
Or write back the hardware clock: hwclock -- systohc

in/etc/rc. d/rc5.d create the xntp Service Startup Script
Linux:/etc/rc. d/rc5.d # ln-s .. /xntpd s14xntpd
View NTP time adjustment record
Linux:/var/log # grep NTP messages
Aug 14 07:19:51 Linux ntpdate [2837]: step time server 10.30.1.105 offset 2.010174 sec
Aug 14 07:19:51 Linux ntpd [2884]: NTPD 4.2.0a@1.1213-r wed Jun 30 18:37:03 UTC 2004 (1)
Aug 14 07:19:51 Linux ntpd [2884]: Precision = 1.000 USEC
Aug 14 07:19:51 Linux ntpd [2884]: listening on interface wildcard, 0.0.0.0 #123
Aug 14 07:19:51 Linux ntpd [2884]: listening on interface wildcard, ::# 123
Aug 14 07:19:51 Linux ntpd [2884]: listening on interface Lo, 127.0.0.1 #123
Aug 14 07:19:51 Linux ntpd [2884]: listening on interface eth0, 10.40.157.66 #123
Aug 14 07:19:51 Linux ntpd [2884]: kernel Time sync status 0040

Mmscbill :~ # Date
Wed May 7 15:53:10 CST 2008
The Time Zone setting is correct. PRC is the name of the time zone, which corresponds to the PRC Time Zone file under/usr/share/lib/zoneinfo.
CST is short for Chinese standard time and is used in the output of the date command. It is defined in the PRC Time Zone file.
The Asia file under/usr/share/lib/zoneinfo/src knows what is going on.

Modify system time (bjchenxu, laixi781211, huhuuworm)
Date-s "CST", CST indicates the time zone, and the time is set to date-S
After modification, execute clock-W to write to CMOS.
Hwclock -- systohc
Set the hardware clock to the current system time

 

Zdump-V Europe/Moscow view some time zone setting parameters

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.