Help information for the date command
[Email protected] source]# date--help
Usage: date [options] ... [+ format]
Or: Date [-u|--utc|--universal] [MMDDHHMM[[CC]YY][.SS]]
Displays the current time in the given format, or sets the system date.
-D,--date= string displays the time described by the specified string, not the current time
-F,--file= date file similar to--date, read-in time description by line from the date file
-R,--reference= file shows the last modified time for file specified file
-R,--rfc-2822 output date and time in RFC 2822 format
Example: August 7, 2006, Monday 12:34:56-0600
--rfc-3339=timespec outputs the date and time in RFC 3339 format.
timespec= ' Date ', ' seconds ', or ' ns '
Represents the display precision of a date and time.
The date and time units are separated by a single space:
2017-12-22 17:38:59-06:00
-S,--set= string sets the specified string to separate the time
-U,--UTC,--universal output or set Coordinated Universal Time
--HELP Display this help message and exit
--version display version information and exit
The given format controls the output, and the sequence is interpreted as follows:
Percent of a text%
%a of the current locale (ex: day, for Sunday)
%A the full name of the current locale (for example: Sunday)
%b the month name of the current locale (for example: one, for January)
%B the full name of the current locale (for example: January)
The date and time of the current locale of%c (for example: March 3, 2005 Thursday 23:05:25)
%c century; For example,%Y, typically omitting the last two digits of the current year (for example: 20)
%d date by month (ex: 01)
%d Date by month; equal to%m/%d/%y
%e date by month, add a space, equal to%_d
%F full date format, equivalent to%y-%m-%d
%g last two bits of the ISO-8601 format year (see%G)
%G ISO-8601 format year (see%V), typically used only with%V
%h equals%b.
%H hours (00-23)
%I Hours (00-12)
%c date by year (001-366)
%k (0-23)
%l (1-12)
%m Month (01-12)
%M points (00-59)
%n line break
%N nanosecond (000000000-999999999)
%p "Morning" or "afternoon" under current locale, output empty when unknown
%P is similar to%P, but outputs lowercase letters
%r 12-hour clock time at current locale (e.g. 11:11:04 pm)
%R 24 hours of time and minutes, equivalent to%h:%m
%s number of seconds since 1970-01-01 00:00:00 UTC time
%s seconds (00-60)
%t Output Tab tab
%T time, equal to%h:%m:%s
%u week, 1 stands for Monday
%u week of the year, with Sunday as the first day of the Week (00-53)
%V ISO-8601 Format Specification for the week of the year, with Monday as the first day of the Week (01-53)
%w Day of the Week (0-6), 0 for Monday
%W Week of the year, with Monday as the first day of every week (00-53)
Date description under the current locale of%x (for example: 12/31/99)
Time description Under current locale of%x (e.g. 23:13:48)
%y year last two digits (00-99)
%Y year
%z +HHMM Digital Time zone (for example,-0400)
%:z +hh:mm Digital Time zone (for example, -04:00)
%::z +HH:MM:SS Digital Time zone (for example, -04:00:00)
%:::z Digital time zone with the necessary precision (for example, -04,+05:30)
%Z time zone abbreviations by alphabet (for example, EDT)
By default, the numeric area of a date is populated with 0.
The following optional tags can be followed by "%" after:
-(hyphen) does not populate the field
_ (underline) fills with spaces
0 (number 0) with 0 padding
^ If possible, use uppercase letters
# if possible, use the opposite case
Also allows an optional field width to be specified after any tag, which is a decimal number.
As an optional cosmetic declaration, it can be E, using the Local environment association if possible
Representation, or O, where possible, using a numeric symbol associated with the local environment.
Time formatted output
[[Email protected] ~]# date "+%y-%m-%d"
2013-02-19
[[Email protected] ~]# date "+%h:%m:%s"
13:13:59
[[Email protected] ~]# date "+%y-%m-%d%h:%m:%s"
2013-02-19 13:14:19
[[Email protected] ~]# date "+%y_%m_%d%h:%m:%s"
2013_02_19 13:14:58
[Email protected] ~]# date-d today
Tue Feb 13:10:38 CST 2013
[Email protected] ~]# date-d now
Tue Feb 13:10:43 CST 2013
[Email protected] ~]# date-d tomorrow
Wed Feb 13:11:06 CST 2013
[Email protected] ~]# date-d yesterday
Mon Feb 13:11:58 CST 2013
Time setting
We generally use the "date-s" command to modify the system time
For example, set the system time to the July 13, 2011 command: Date-s 07/13/2011
Set the system time to 11 points 12 minutes 0 seconds command: date-s 11:12:00
Note: This is about system time and Linux is maintained by the operating system.
When the system starts, the Linux operating system reads the time from the CMOS into the system time variable, and the later modification time is realized by modifying the system time. To keep the system time consistent with the CMOS time, Linux writes the system time to CMOS at every time. Since this synchronization takes place at intervals (about 11 minutes), if the machine is re-started immediately after we execute the DATE-S, the modification time may not be written to the CMOS, which is the cause of the problem.
You can execute the following command if you want to make sure that the changes take effect.
#clock –w
This command forces the system time to be written to the CMOS.
Use of the Linux date