How to modify the time zone and time in Linux

Source: Internet
Author: User
Tags time and date

There are two clocks in linux, but the time zone in linux is somewhat different from that in China. Let's take a look at how to modify and view the time zone and Time Zone in Linux.


1. Modify the time zone

1. view the current time zone

Date-R

2. Modify the time zone

Use tzselect to select the target time zone

Tzselect

Select the corresponding time zone as prompted and get the time zone settings, for example, TZ = 'Asia/Shanghai'; export TZ
Asia/Shanghai is the time zone setting method.

3. Copy the corresponding time zone file, replace the CentOS System Time Zone file, or create a link file.

Cp/usr/share/zoneinfo/$ main Time Zone/$ Time Zone/etc/localtime

Available in China:

Cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime


4. modify the content in/etc/sysconfig/clock.

ShellZONE = "Asia/Shanghai"
UTC = true
ARC = false


If UTC = true is not added, the time zone in this configuration will not be applied to the system time zone when the system starts. Otherwise, the system will check the settings in this configuration when the system starts, apply the time ZONE settings in ZONE to the system time ZONE, and the system time ZONE will change accordingly.

Ii. modification time

1. view the time and date

Date

2. Set the time and date

Set the CentOS system date to the June 10, 1996 command

Data-s 06/22/96

Set the CentOS system time to 01:52:00 P.M..

Date-s 13:52:00

3. Write the current time and date to the BIOS to prevent failure after restart

Hwclock-w

Iii. Enable NTP synchronization time

Yum install ntpdate
Ntpdate cn.pool.ntp.org

Chkconfig -- level 3 ntpd on

 

Linux loading time zone and time:

When Linux is started, a script (/etc/rc. d/rc. sysinit) runs the/sbin/hwclock program to copy the current hardware clock to the system time. The script file reads the time zone configuration file/etc/sysconfig/clock. Therefore, you can directly modify the configuration file without modifying the script, and set the UTC line as needed, set to true or false.

4. modify the system time zone:

1. tzselect can modify the configuration file/etc/sysconfig/clock according to the command prompt.


However, in actual work, it is found that this method cannot make the time settings on the server take effect immediately, and ntpdate cannot be used to synchronize the time on the server. Even if you use the date command to manually set the time, if you use ntpdate for time synchronization, the time will be changed to the time in the original wrong time zone. Production machines are often very important and cannot be restarted.

 

2. If you want to modify the time zone and it will take effect immediately, you can copy the corresponding time zone file to replace the default time zone of the system:

# Cp/usr/share/zoneinfo/$ main Time Zone/$ Time Zone/etc/localtime

For Chinese servers, run:

# Cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime

In fact, you can add a soft connection, but it is usually a copy. The soft connection method is as follows:

Ln-sf/usr/share/zoneinfo/Asia/Shanghai/etc/localtime


Then, write the current time to the BIOS to take effect permanently (to avoid invalidation after restart)

# Hwclock

5. modify the system time

Date-s
For example, the command to set the system time to June 10, 1996 is as follows.
# Data-s 06/10/96
The command to set the system time to 01:12:00 P.M. is as follows.
# Date-s 13:12:00


# Clock-w
This command forces the system time to be written to CMOS

Related Article

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.