The Linux clock is divided into the system clock and the hardware clock (Real time clock, referred to as RTC). The system clock is the clock in the current Linux kernel, while the hardware clock is the battery-powered clock on the motherboard and the hardware clock can be set in the BIOS. When Linux starts, the system clock reads the settings of the hardware clock, and the system clock operates independently of the hardware clock.
1. Date--used to read or set the system time
2. Hwclock--used to read or set hardware time
All commands in Linux, including functions, are the system clock settings used. In Linux, the commands for clock viewing and setting are mainly date, Hwclock.
1. Date
Name: Date
Usage rights: All users
How to use:
Date [-u] [-D DATESTR] [-S datestr] [--UTC] [--universal] [--DATE=DATESTR] [--SET=DATESTR] [--help] [--version] [+format] [MMDDHHMM[[CC]YY][.SS]]
Description
Date can be used to display or set the system's Day and time, in terms of display, the user can set the format to be displayed, the format is set to a plus sign followed by a number of tags, where the list of available tags is as follows:
In terms of time:
%: Printed%
%n: Next line
%t: Jump Grid
%H: Hours (00-23)
%I: Hours (01-12)
%k: Hours (0-23)
%l: Hours (1-12)
%M: minutes (00-59)
%p: Show local AM or PM
%r: Direct Display time (12-hour format, HH:MM:SS [ap]m)
%s: Number of seconds from January 1, 1970 00:00:00 UTC to date
%s: Seconds (00-60)
%T: Direct Display time (24-hour system)
%x: Equivalent to%h:%m:%s
%Z: Show Time zone
Date aspects:
%a: Day of the Week (SUN-SAT)
%A: Day of the Week (Sunday-saturday)
%b: Month (JAN-DEC)
%B: Month (january-december)
%c: Display date and time directly
%d: Day (01-31)
%d: Show date directly (MM/DD/YY)
%h: With%b
%j: The first day of the Year (001-366)
%m: Month (01-12)
%u: Week of the Year (00-53) (Sunday is the first day of the week)
%w: Day of the Week (0-6)
%W: Week of the Year (00-53) (with Monday as the first day of the week)
%x: Show date directly (MM/DD/YY)
%y: Last two digits of the year (00.99)
%Y: Full year (0000-9999)
If you do not start with a plus, it means to set the time, and the time format is MMDDHHMM[[CC]YY][.SS], where mm is the month, DD is the day, HH is the hour, MM is minutes, CC is the first two digits of the year, YY is the year after two digits, SS is the number of seconds
Parameters:
-D datestr: Displays the time set in the DATESTR (non-system time)
--HELP: Display Auxiliary message
-S DATESTR: Set the system time to the time set in Datestr
-U: Show current GMT
--version: Show version number
Example:
Show time after Skip, and then
Show current date: #date ' +%t%n%d '
Display month and day: Date ' +%b%d '
Display date and set time (12:34:56): #date--date ' 12:34:56 '
Note: When you don't want to have a meaningless 0 o'clock (say, 1999/03/07), you can insert a symbol into the tag, for example, Date ' +%-h:%-m:%-s ' will remove the meaningless 0 in seconds and minutes, as if the original 08:09:04 would change to 8:9:4. In addition, the system time can be set only if the authority (for example, Root) is acquired.
When you change the system time as root, remember to use CLOCK-W to write the system time to the CMOS so that the system time will continue to hold the latest correct value the next time you reboot.
Example: Modify Date Time
At the command line, enter:
Date: Display current time Fri 3 14:15:16 CST 2007
Date–s: Modify Time by string
Can only modify the date, do not modify the time, enter: Date-s 2007-08-03
Only modified time, input: Date-s 14:15:00
Also modify the date time, note to add double quotation marks, the date and time there is a space between, enter:
#date-S "2007-08-03 14:15:00"
2. View hardware Time
# Hwclock
Set Hardware time
# hwclock-set-date= "07/07/06 10:19" (Month/day/year: minutes: seconds)
3. Synchronization of hardware time and system time
According to the foregoing, reboot the system, hardware time will read the system time, to achieve synchronization, but do not restart, you need to use the Hwclock command to achieve synchronization.
The hardware clock is synchronized with the system clock:
# Hwclock--hctosys (HC stands for hardware time, SYS represents system time)
system clock and Hardware clock synchronization: (To synchronize the system's time to the hardware clock)
# HWCLOCK–SYSTOHC