3.3. Using the hwclock Command
hwclock is a utility for accessing the hardware clock, also referred to as the Real Time Clock (RTC). The hardware clock is independent of the operating system you use and works even when the machine is shut down. This utility is used for displaying the time from the hardware clock. hwclock also contains facilities for compensating for systematic drift in the hardware clock.
hwclock utility saves its settings in the /etc/adjtime file, which is created with the first change you make, for example, when you set the time manually or synchronize the hardware clock with the system time.
Note
hwclock command was run automatically on every system shutdown or reboot, but it is not in Red Hat Enterprise Linux 7. When the system clock is synchronized by the Network Time Protocol (NTP) or Precision Time Protocol (PTP), the kernel automatically synchronizes the hardware clock to the system clock every 11 minutes.
3.3.1. Displaying the Current Date and Time
hwclock with no command line options as the root user returns the date and time in local time to standard output.
hwclock--utc or --localtime options with the hwclock command does not mean you are displaying the hardware clock time in UTC or local time. These options are used for setting the hardware clock to keep time in either of them. The time is always displayed in local time. Additionally, using the hwclock --utc or hwclock --local commands does not change the record in the /etc/adjtime file. This command can be useful when you know that the setting saved in /etc/adjtime is incorrect but you do not want to change the setting. On the other hand, you may receive misleading information if you use the command an incorrect way. See the hwclock(8) manual page for more details.
Example 3.9. Displaying the Current Date and Time
root:
~]# hwclock
Tue 15 Apr 2017 04:23:46 PM CEST -0.329272 seconds3.3.2. Setting the Date and Time
--set and --date options along with your specification:
hwclock --set --date "dd mmm yyyy HH:MM"--utc or --localtime options, respectively. In this case, UTC or LOCAL is recorded in the /etc/adjtime file.
Example 3.10. Setting the Hardware Clock to a Specific Date and Time
root in the following format:
~]# hwclock --set --date "21 Oct 2016 21:17" --utc3.3.3. Synchronizing the Date and Time
- Either you can set the hardware clock to the current system time by using this command:
hwclock --systohcNote that if you use NTP, the hardware clock is automatically synchronized to the system clock every 11 minutes, and this command is useful only at boot time to get a reasonable initial system time. - Or, you can set the system time from the hardware clock by using the following command:
hwclock --hctosys
--utc or --localtime option. Similarly to using --set, UTC or LOCAL is recorded in the /etc/adjtime file.
hwclock --systohc --utc command is functionally similar to timedatectl set-local-rtc false and the hwclock --systohc --local command is an alternative to timedatectl set-local-rtc true.
Example 3.11. Synchronizing the Hardware Clock with System Time
root:
~]# hwclock --systohc --localtime
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.