HowTo: Linux Server Change OR Setup The Timezone
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HowTo: Linux Server Change OR Setup The Timezone相关的知识,希望对你有一定的参考价值。
My Linux systems timezone is pointing to the wrong timezone. How do I setup or change the timezone under Linux operating systems?
Unix time, or POSIX time, is a system for describing points in time: it
is the number of seconds elapsed since midnight UTC on the morning of
January 1, 1970, not counting leap seconds. The definition for time
zones can be written in short form as UTC?±n (or GMT?±n), where n is the
offset in hours. You can use the following commands:
[a] setup or redhat-config-date for RHEL based distros.
[b] dpkg-reconfigure tzdata for Debian based distros.
[c] ln command – Generic method for all other distros.
Command to change the Linux timezone
You need to type the following commands as per your Linux distribution.
If you are using Fedora / RHEL / Cent OS Linux
Type the redhat-config-date command at the command line to start the time and date properties tool, run:
# redhat-config-date
OR type setup and select time zone configuration. This tool is recommended for remote ssh text based sessions.
# setup
Select timezone configuration
Fig.01: Redhat / CentOS Server Setting Up Timezone
Just follow on screen instructions to change the timezone.
If you are using Debian / Ubuntu Linux
To change the timezone for you run the following command as root user:
# dpkg-reconfigure tzdata
Again, just follow on screen instructions.
Set timezone using /etc/localtime configuration file [any Linux distro]
Often /etc/localtime is a symlink to the file localtime or to the correct time zone file in the system time zone directory.
Generic procedure to change timezone under Linux
Cd to /etc, run:
# cd /etc
Create a symlink to file localtime:
# ln -sf /usr/share/zoneinfo/EST localtime
OR some distro use /usr/share/zoneinfo/dirname/zonefile format (Red hat and friends):
# ln -sf /usr/share/zoneinfo/EST localtime
OR if you want to set up it to IST (Asia/Calcutta):
# ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime
Please note that in above example you need to use directory structure
i.e. if you want to set the timezone to Calcutta (India) which is
located in the Asia directory.
How do I verify new settings?
Use the date command to verify that your timezone is changed:
$ date
Output:
Tue Aug 27 14:46:08 EST 2006
How do I use of environment variable called TZ?
You can use TZ environment variable to display date and time according to your timezone:
$ export TZ=America/Los_Angeles
$ date
Sample Output:
Thu Aug 27 11:10:08 PST 2006
转自:https://www.cyberciti.biz/faq/howto-linux-unix-change-setup-timezone-tz-variable/
以上是关于HowTo: Linux Server Change OR Setup The Timezone的主要内容,如果未能解决你的问题,请参考以下文章
markdown HowTo:找出我的Linux发行版名称和版本
markdown Howto:在VirtualBox OSX上安装Alpine Linux 3.3
如何配置使用串口设备登录linux终端Linux Serial Console HOWTO
sh 监控并重新启动Varnish - 来自http://www.cyberciti.biz/tips/howto-linux-unix-write-to-syslog.html的脚本