How To Set or Change Timezone/Date/Time on Ubuntu 18.04

Introduction

Modern operating systems detect and synchronize time using NIST (National Institute of Standards and Technology) time servers. NIST operates an atomic clock that neither gains nor loses a second in 300 million years.

However, you may find that your system is not synchronizing with NIST time servers properly.

This guide shows you how to check, change the time, date, and timezone in Ubuntu.

how to set the time, date, and timezone in Ubuntu tutorial

Prerequisites

  • Some operations may require sudo or root privileges
  • The command line/terminal window (Ctrl-Alt-T)

Most modern distributions such as Fedora, Debian, Ubuntu, Arch, CentOS v.7.x+, and other Unix-based systems use the timedatectl utility. This command allows you to control and edit time and date settings using the command line.

Using timedatectl to Control the System Time and Date

Display Current Date and Time with timedatectl

To display the current time and date information use the command:

timedatectl

The output provides local and universal time, timezone, and informs you if the synchronization process is enabled.

current time and date in Ubuntu

Sync Time to NIST Atomic Clock

You can set your Ubuntu system to synchronize to the NIST atomic clock:

timedatectl set-ntp yes

If you need to turn off NTP synchronizing to be able to adjust the time and date manually, use:

timedatectl set-ntp no

Note: NTP stands for Network Time Protocol.

How to Change the Time

This simple command sets the time to your specifications. For it to work, the automatic time synchronization needs to be disabled as discussed previously.

timedatectl set-time 21:45:53

The time format should be in HH:MM:SS (Hours, Minutes, Seconds).

How to Change the Date

The same command is used to define the date as well:

timedatectl set-time 2019-04-10

The date should be formatted as YYYY-MM-DD (Year, Month, and Day).

How to Set a Timezone in Ubuntu

The timedatectl command additionally allows you to synchronize your systems with a timezone of your choosing. These are the steps:

1. To list out the names of the timezones:

timedatectl list-timezones
list of all the timezones available for date and time

2. Find the location closest to you, then enter the following:

timedatectl set-timezone Region/Location

3. Replace Region/Location with a name from the timezone list.

The timezone list is extensive. You may want to filter the list by keyword, using grep:

timedatectl list-timezones | grep keyword
setting time zone using grep

The | is a pipe symbol, usually next to the Enter key. You can substitute keyword for any keyword you wish, such as America, Asia, or New_York.  If you get an error, double-check your spelling and make sure that you are using capital letters correctly.

How to Set Universal Time (UTC) in Ubuntu

UTC stands for Coordinated Universal Time and is used for scientific calculations and synchronizing between timezones across the globe. You can synchronize your system by entering the following command:

timedatectl set-timezone UTC

There is no immediate output; however, you can check if the settings applied by using timedatectl.

Note: GMT and Zulu Time are often used to refer to UTC. They are equivalent terms when fractions of a second are not relevant.

How to Sync Hardware Clock

RTC stands for Real-Time Clock, another name for the hardware clock in your computer. Your system has a tiny quartz crystal and a battery that keeps time at times when the system disconnects from a network.

Set Hardware Clock to Sync to Local Timezone

To have your Real-Time Clock synchronize to your local timezone enter:

timedatectl set-local-rtc 1

You may get an error in this mode, since updating the hardware clock to the local timezone is unsupported.

Set the Hardware Clock to Sync with UTC

If necessary, you can set your hardware clock to synchronize with UTC by entering the following command:

timedatectl set-local-rtc 0

As with the previous command, there is no confirmation that the change has applied. You need to verify the change manually by using the timedatectl command.

Set Time, Date Timezone in Ubuntu Older Versions From Command Line

Older Ubuntu versions may not support the timedatectl command. Find out how to get the Ubuntu version.

You can still display and adjust system time setting from a command line by using the commands listed below:

  • To display the date and time of the operating system use:
date
  • Change the date of the operating system by typing:
sudo date -s YY-MM-DD HH:MM:SS

Replace YY-MM-DD with Year-Month-Day, and HH:MM:SS with Hour:Minute:Second. You can set just the date or only the time, depending on your needs.

  • Display the time kept by the hardware clock (RTC) by using any of the following commands:
sudo hwclock -r

or

sudo hwclock --show

or

sudo hwclock --show --verbose

Note: Some versions may not support the –-verbose option, and it may not work on a virtual machine. The hardware clock may not hold the same time as the operating system.

  • Display the RTC time in UTC format:
sudo hwclock --show --utc
  • Change the time kept by the RTC:
sudo hwclock --set --date MM/DD/YY HH:MM:SS
  • Set OS time based on the hardware clock (RTC):
sudo hwclock --hctosys

This command tells the system to set the HC (hardware clock) to SYS (system):

  • Set the RTC based on the operating system time:
sudo hwclock --systohc

Use this command to reverse the previous process.

Conclusion

This guide showed you how to set the time,  date, and timezone on your Ubuntu system. As we learned, setting your system to synchronize with NTP is typically the best course of action.

原创文章,作者:745907710,如若转载,请注明出处:https://blog.ytso.com/223965.html

(0)
上一篇 2022年1月7日
下一篇 2022年1月7日

相关推荐

发表回复

登录后才能评论