Linux The clock is divided into the system clock and the hardware (Real time clock, or RTC) clock. The system clock is the clock in the current Linux kernel, and the hardware clock is a battery-powered clock on the motherboard that can be set in the BIOS. When Linux starts, the hardware clock reads the settings of the system clock, and the system clock is independent of the hardware.
Linux all of the commands (including functions) in the system clock settings are used. In Linux, the commands for clock viewing and setting are mainly date, Hwclock.
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 date and time of the system, in terms of display, the user can set the format to be displayed, the format is set to a plus followed by a number of tokens, where the list of available tags is as follows:
in terms of time:
% :Print%
%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 sign, you want to set the time, and the time format is MMDDHHMM[[CC]YY][.SS]
where MM DD for hours, mm for minutes, CC SS is the number of seconds
parameter :
show the time set in 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:
1 . 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
This article is from the "Study-everyday" blog, make sure to keep this source http://studys.blog.51cto.com/9736817/1605151
Setup date for Linux time