linux查询时区的命令
-
Linux查询时区的命令为`timedatectl`。
使用`timedatectl`命令可以查询当前系统的时区设置。具体步骤如下:
1. 打开终端,输入命令`timedatectl`,并按下回车键。
2. 终端会显示当前系统的时间、日期、时区等相关信息。
3. 在输出的信息中,找到名为”Time zone”的字段,即为当前系统设定的时区。
此外,还可以使用命令`date -R`查询当前系统的时区信息。使用该命令后,终端会显示当前系统的日期和时间,并以”GMT”或者”+/-时区偏差”的形式显示时区信息。
注意:查询时区信息需要具备管理员权限,如普通用户需要使用`sudo`命令来执行查询时区的命令。
2年前 -
在Linux系统中,可以使用以下命令来查询当前的时区:
1. `date`命令:执行`date`命令,会显示系统当前的日期和时间,其中包括时区信息。例如:
“`
$ date
Fri Apr 23 09:30:12 CST 2021
“`
这里的”CST”代表中国标准时间。2. `/etc/timezone`文件:这个文件存储了系统当前所使用的时区信息。可以使用文本编辑器打开这个文件,查看其中的内容。例如:
“`
$ cat /etc/timezone
Asia/Shanghai
“`
这里的”Asia/Shanghai”表示当前时区为亚洲/上海。3. `/etc/localtime`文件:系统的时区信息也可以通过查看`/etc/localtime`文件来获取。这个文件实际上是一个指向时区信息文件的软链接。可以使用`ls`命令来查看它所指向的文件的路径。例如:
“`
$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 37 Apr 23 09:32 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
“`
这里可以看到`/etc/localtime`指向的是`/usr/share/zoneinfo/Asia/Shanghai`,表示当前时区为亚洲/上海。4. `timedatectl`命令:`timedatectl`是系统时间和日期管理工具,可以用来查询和设置时区。执行以下命令来查看当前时区信息:
“`
$ timedatectl
Local time: Fri 2021-04-23 09:35:49 CST
Universal time: Fri 2021-04-23 01:35:49 UTC
RTC time: Fri 2021-04-23 01:35:50
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
“`
这里的”Time zone”项显示当前时区为亚洲/上海。5. `tzselect`命令:`tzselect`是一个交互式命令,可以用来选择系统的时区并生成相应的`/etc/localtime`文件。执行命令后,会提示你选择所在地区的大洲和城市,根据提示进行选择即可。选择完成后,会输出所选时区的信息,包括时区文件的路径和文件名。例如:
“`
$ tzselect
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none – I want to specify the time zone using the Posix TZ format.
#? 5Please select a country.
1) Afghanistan 18) Georgia 35) Palestine
2) Armenia 19) Hong Kong 36) Philippines
3) Azerbaijan 20) Hovd 37) Qatar
4) Bahrain 21) India 38) Russia
…
#? 21Please select one of the following time zone regions.
1) Kolkata (also used in India)
2) Mumbai
3) Kolkata
#? 2The following information has been given:
Mumbai
Therefore TZ=’Asia/Kolkata’ will be used.
Local time is now: Fri 23 Apr 2021 10:04:41 AM IST.
Universal Time is now: Fri 23 Apr 2021 04:34:41 AM UTC.
Is the above information OK?
1) Yes
2) No
#? 1You can make this change permanent for yourself by appending the line
TZ=’Asia/Kolkata’; 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/Kolkata
“`
这里选择了亚洲大陆,印度国家和孟买城市,最后输出了所选时区的信息和时区文件的路径。以上是在Linux系统中查询时区的几种方法,可以根据具体需求选择适合的方法来查看当前的时区信息。
2年前 -
在Linux系统中,可以使用多种命令来查询系统的时区设置。以下是其中几种常用的方法:
1. 使用`timedatectl`命令:
– 打开终端,输入命令`timedatectl`。
– 在输出结果中,找到所需的时区信息,显示为”Time zone”。2. 使用`date`命令:
– 打开终端,输入命令`date`。
– 输出结果中的时区信息显示为`UTC`或以`GMT`开头,例如`GMT+8`表示东八区,即北京时间。3. 查看`/etc/localtime`软链接指向的时区文件:
– 打开终端,输入命令`ls -l /etc/localtime`。
– 输出结果中的文件路径即为当前系统所使用的时区文件。4. 查看`/etc/timezone`文件:
– 打开终端,输入命令`cat /etc/timezone`。
– 输出结果即为当前系统的时区。5. 查看`/etc/sysconfig/clock`文件:
– 打开终端,输入命令`cat /etc/sysconfig/clock`。
– 输出结果中的`ZONE`参数即为当前系统的时区,值为时区标识符,例如`ZONE=”Asia/Shanghai”`表示使用亚洲/上海时区。总结:以上是几种常用的查询Linux系统时区的方法,根据具体情况可以选择合适的命令来查看时区设置。
2年前