Home  >  Article  >  Operation and Maintenance  >  What are the methods to change the system time zone in Centos7?

What are the methods to change the system time zone in Centos7?

青灯夜游
青灯夜游Original
2023-03-03 10:47:4918057browse

Two methods for modifying the system time zone in Centos7: 1. Use the timedatectl command to set and modify time zone information, the syntax is "timedatectl set-timezone time zone identification"; 2. Modify ".bash_profile" in the user directory file, append "TZ='time zone identifier'; export TZ" at the end of the file.

What are the methods to change the system time zone in Centos7?

#The operating environment of this tutorial: centos7 system, thinkpad t480 computer.

Two methods to modify the Centos7 system time zone

Note: After modifying the time zone of the Linux system, and then install jvm, the jvm will use the system by default time zone.

If the system time zone is set incorrectly, after installing the jvm, modify the system time zone, but the jvm time zone will remain unchanged unless the jvm startup parameter is added: -D user.timezone=GMT 08

Method 1: timedatectl set-timezone Asia/Shanghai

timedatectl is a command under Linux, used to control the system time and date. It can be used to query and change the system clock and settings, and can also set and modify time zone information.

# timedatectl
Warning: Ignoring the TZ variable. Reading the system's time zone setting only.

Local time: Mon 2016-11-21 01:52:42 EST
Universal time: Mon 2016-11-21 06:52:42 UTC
RTC time: Mon 2016-11-21 06:52:42
Time zone: America/New_York (EST, -0500)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: no
Last DST change: DST ended at
Sun 2016-11-06 01:59:59 EDT
Sun 2016-11-06 01:00:00 EST
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2017-03-12 01:59:59 EST
Sun 2017-03-12 03:00:00 EDT

Set the time zone to CST (East 8th District)

# timedatectl  set-timezone Asia/Shanghai
Warning: Ignoring the TZ variable. Reading the system's time zone setting only.

Local time: Mon 2016-11-21 14:52:59 CST
Universal time: Mon 2016-11-21 06:52:59 UTC
RTC time: Mon 2016-11-21 06:52:59
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@localhost ~]#

Method 2: TZ environment variable method

Modify .bash_profile in the user directory , append at the end of the file:

TZ='Asia/Shanghai'; export TZ

After logging out, log in again, and use the date command to see the effect.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What are the methods to change the system time zone in Centos7?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn