Difference between revisions of "Redhat7:date"
Jump to navigation
Jump to search
| (3 intermediate revisions by the same user not shown) | |||
| Line 8: | Line 8: | ||
| − | == timedatectl command == | + | == <tt>timedatectl</tt> command == |
As with the other ctl command the timedateclt works in a similar way. | As with the other ctl command the timedateclt works in a similar way. | ||
| Line 26: | Line 26: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | == date command == | + | == <tt>date</tt> command == |
<syntaxhighlight> | <syntaxhighlight> | ||
| Line 35: | Line 35: | ||
#set time | #set time | ||
date +%T -s HH:MM:SS | date +%T -s HH:MM:SS | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | == <tt>hwclock</tt> command == | ||
| + | |||
| + | '''Note:''' In Red Hat Enterprise Linux 6, the hwclock command was run automatically on every system shutdown or reboot, but it is not in Red Hat Enterprise Linux 7. | ||
| + | |||
| + | <syntaxhighlight> | ||
| + | #Display current time and date | ||
| + | hwclock | ||
| + | hwclock --utc | ||
| + | hwclock --localtime | ||
| + | |||
| + | #set date and time | ||
| + | hwclock --set --date "dd mmm yyyy HH:MM" | ||
| + | |||
| + | #sync system clock to hw clock | ||
| + | hwclock --systohc --localtime | ||
| + | hwclock --systohc --utc | ||
| + | |||
| + | #sync hw clock to system clock | ||
| + | hwclock --hctosys --localtime | ||
| + | |||
| + | #reboot the system for changes to take effect | ||
| + | reboot | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 10:04, 23 February 2015
Types of Clocks
There are two separate clocks on a system, and most modern OS's distinguish between them.
- Real-Time Clock - Also know as the hardware clock, this clock runs independently of the OS, and continues even when the system is shotdown
- System Clock - Maintained by the kernel of the OS. This can be set to use Univerisal Time (UTC) or the local time. It is recommended to us UTC.
timedatectl command
As with the other ctl command the timedateclt works in a similar way.
#Display current time and date
timedatectl
#set date
timedatectl set-time YYYY-MM-DD
#set time
timedatectl set-time HH:MM:SS
# set time zone
timedatectl list-timezones
timedatectl set-timezone time_zone
# Synchronise using ntp
timedatectl set-ntp booleandate command
#Display current time and date
date --utc
#set date
date +%F -s YYYY-MM-DD
#set time
date +%T -s HH:MM:SShwclock command
Note: In Red Hat Enterprise Linux 6, the hwclock command was run automatically on every system shutdown or reboot, but it is not in Red Hat Enterprise Linux 7.
#Display current time and date
hwclock
hwclock --utc
hwclock --localtime
#set date and time
hwclock --set --date "dd mmm yyyy HH:MM"
#sync system clock to hw clock
hwclock --systohc --localtime
hwclock --systohc --utc
#sync hw clock to system clock
hwclock --hctosys --localtime
#reboot the system for changes to take effect
reboot