linux设置时区和时间
How to set date, time and timezone on Linux/Unix box will be introduced in this post.
本文将介绍如何在Linux / Unix机顶盒上设置日期,时间和时区。
Unix time, or POSIX time which is a system for describing points in time is the number of seconds elapsed since midnight UTC on the morning of January 1, 1970, not counting leap seconds.
Unix时间(即POSIX时间,它是用于描述时间点的系统)是自1970年1月1日凌晨UTC以来经过的秒数,不包括seconds秒。
The number of seconds elapsed can be got by this command on Linux/Unix systems:
在Linux / Unix 系统上,此命令可以获取经过的秒数:
$ date +%s
设定Linux日期 (Set Linux date)
Linux date can be set using following syntax:
可以使用以下语法设置Linux日期:
# date +%Y%m%d -s "yyyymmdd"
yyyy is year, mm is month and dd is day.
yyyy是年,mm是月,dd是天。
For example, we can set the date to June 22, 2010 by:
例如,我们可以通过以下方式将日期设置为2010年6月22日:
# date +%Y%m%d -s "20100622"
设定Linux时间 (Set Linux time)
Linux time can be set using following syntax:
可以使用以下语法设置Linux时间:
# date +%T -s "hh:mm:ss"
hh is hour, mm is minite and ss is second.
hh是小时,mm是微小的,ss是秒。
For example, we can set the time to 11:28 by:
例如,我们可以通过以下方式将时间设置为11:28:
# date +%T -s "11:28:00"
设置Linux日期和时间 (Set Linux date and time)
The date and time can be set by date command at the same time by:
日期和时间可以通过date命令同时设置:
# date mmddhhmmyyyy.ss
The first mm means month while the second mm means minite.
第一个毫米表示月份,第二个毫米表示分钟。
For example, we can set the date and time to 11:28 on June 22, 2010 by:
例如,我们可以通过以下方式将日期和时间设置为2010年6月22日的11:28:
# date 062211282010.00
Another way to set new date and time is using the following syntax:
设置新日期和时间的另一种方法是使用以下语法:
# date --set="STRING"
The method to set the date and time above is:
上面设置日期和时间的方法是:
# date -s "22 JUN 2010 11:28:00"
or
要么
# date --set="22 JUN 2010 11:28:00"
设置Linux时区 (Set Linux timezone)
The configuration file for timezone is usally /etc/localtime which is often a symlink to the file localtime or to the correct time zone file in the system. The time zone directory is /usr/share/zoneinfo where you can find a list of time zone regions. In some distro such as Fedora/RHEL/Cent OS, the zone files use /usr/share/zoneinfo/REGION/CITY like format.
时区的配置文件通常是/ etc / localtime ,通常是到文件localtime或系统中正确的时区文件的符号链接。 时区目录是/ usr / share / zoneinfo ,您可以在其中找到时区区域列表。 在某些发行版(例如Fedora / RHEL / Cent OS)中,区域文件使用/ usr / share / zoneinfo / REGION / CITY之类的格式。
The method for setting Linux timezone:
设置Linux时区的方法:
如果需要,请备份旧时区信息 (Backup old timezone info if needed)
# mv /etc/localtime /etc/localtime.bak
从/ etc / localtime中找出合适的时区,并创建一个指向它的符号链接 (Find out the appropriate timezone from /etc/localtime and create a symbolic link to it)
For example we want to set the time zone to Hong Kong time:
例如,我们要将时区设置为香港时间:
# ln -sf /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
确认时区已更改 (Verify the timezone is changed)
$ date
You may get a output like this:
您可能会得到如下输出:
$ date
Tue Jun 22 12:33:10 HKT 2010
一些相关的实用程序 (Some related utilities)
Here is some related Linux time/date related utilities.
这是一些与Linux时间/日期相关的实用程序。
通过rdate更新当前系统时间 (Update the current system time by rdate)
# rdate -s time.nist.gov
For a list of available time servers, please check NIST Internet Time Servers.
有关可用时间服务器的列表,请检查NIST Internet时间服务器 。
设置硬件时钟 (Set the hardware clock)
# /sbin/hwclock --systohc
Fedora / RHEL / CentOS具有日期/时间设置工具 (Fedora/RHEL/CentOS have a date/time setting tool)
You can use the GUI tool on Red Hat’s distros:
您可以在Red Hat发行版上使用GUI工具:
# system-config-date
Or try:
或尝试:
# setup
and then select the timezone entry.
然后选择时区条目。
翻译自: https://www.systutorials.com/linux-setting-date-time-and-timezone/
linux设置时区和时间