使用timedatectl命令设置时间

转自:https://www.tecmint.com/set-time-timezone-and-synchronize-time-using-timedatectl-command/

1. To display the current time and date on your system, use the timedatectl command from the commandline as follows:

# timedatectl  status
Check Time and Date

Check Time and Date

In the scrrentcast above, RTC time: is the hardware clock time.

2. The time on your Linux system is always managed through the timezone set on the system, to view your current timezone, do it as follows:

# timedatectl 
OR
# timedatectl | grep Time
Check Linux Time Zone

Check Linux Time Zone

3. To view all available timezones, run the command below:

# timedatectl list-timezones
List All Timezones in Linux

List All Timezones in Linux

4. To find the local timezone according to your location, run the following command:

# timedatectl list-timezones |  egrep  -o “Asia/B.*”
# timedatectl list-timezones |  egrep  -o “Europe/L.*”
# timedatectl list-timezones |  egrep  -o “America/N.*”
Find Local Timezone in Linux

Find Local Timezone in Linux

5. To set your local timezone in Linux, we will use set-timezone switch as shown below.

# timedatectl set-timezone “Asia/Kolkata”
Set Local Timezone in Linux

Set Local Timezone in Linux

It is always recommended to use and set the coordinated universal time, UTC.

# timedatectl set-timezone UTC
Set UTC Time in Linux

Set UTC Time in Linux

You need to type the correct name timezone other wise you may get errors when changing the timezone, in the following example, the timezone “Asia/Kalkata” is not correct therefore causing the error.

Set Correct Timezone in Linux

Set Correct Timezone in Linux

How to Set Time and Date in Linux

6. You can set the date and time on your system, using the timedatectl command as follows:

Set Time in Linux

To set time only, we can use set-time switch along the format of time in HH:MM:SS (Hour, Minute and Seconds).

# timedatectl set-time 15:58:30
Set Local Time in Linux

Set Local Time in Linux

Set Date in Linux

7. To set date only, we can use set-time switch along the format of date in YY:MM:DD (Year, Month, Day).

# timedatectl set-time 20151120
Set Date in Linux

Set Date in Linux

8. To set both date and time:

# timedatectl set-time '16:10:40 2015-11-20'
Set Date and Time in Linux

Set Date and Time in Linux

How to Find and Set Hardware Clock in Linux

9. To set your hardware clock to coordinated universal time, UTC, use the set-local-rtc boolean-value option as follows:

First Find out if your hardware clock is set to local timezone:

# timedatectl | grep local

Set your hardware clock to local timezone:

# timedatectl set-local-rtc 1
Set Hardware Clock Timezone

Set Hardware Clock Timezone

Set your hardware clock to coordinated universal time (UTC):

# timedatectl set-local-rtc 0
Set Hardware Clock to UTC

Set Hardware Clock to UTC

Synchronizing Linux System Clock with a Remote NTP Server

NTP stands for Network Time Protocol is a internet protocol, which is used to synchronize system clock between computers. The timedatectl utility enables you to automatically sync your Linux system clock with a remote group of servers using NTP.

Please note that, you must have NTP installed on the system to enable automatic time synchronization with NTP servers.

To start automatic time synchronization with remote NTP server, type the following command at the terminal.

# timedatectl set-ntp true

To disable NTP time synchronization, type the following command at the terminal.

# timedatectl set-ntp false

Summary

These are very easy examples described in this tutorial and I hope you will find them helpful for setting various Linux system clocks and timezones. To learn more about this tool, head over to timedatectl man page.

If you have anything to say about this article, feel free to leave a comment for any more information to add. Stay connected to Tecmint.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值