The use of the date command
1. Used to display a special time format that can be used to name the log file
2. Used to set the time, but this is relatively small, because the general server is set to have automatic synchronization network time
Usage:
Date [OPTION] ... [+format]
Date [-u|--utc|--universal] [MMDDHHMM[[CC]YY][.SS]]
Parameters:
-D,--date=string displays the time indicated by string, and string is a readable string that compares with each other, such as "2012-06-16 18:31:00" or "next Thursday", This string usually contains the calendar time, time, day of the week, date, relative time, relative date, or number.
[[Email protected] ~]# date +%f2015-11-04[[email protected] ~]# date-d ' +1 day ' +%f2015-11-05[[email protected] ~]# date -d ' +1 month ' +%f 2015-12-04[[email protected] ~]# date-d '-2 year ' +%f
-F,--file=datefile and-D are similar, date-d operations on each line in the file Datefile
-itimespec,--iso-8601[=timespec] Displays the time/date in ISO 8601 format. timespec= ' Date ' only displays the date, ' hours ', ' minutes ', or ' seconds ' displays the corresponding precision. --iso-8601 is equivalent to ' date ' without timespec.
-R, --reference= file displays the last modified time
-R,--rfc-822 output and RFC-822 time string
-S,--set=string sets the time specified by string
[[email protected] ~]# date-s "2008-8-8 20:08:08" Fri 8 20:08:08 CST 2008[[email protected] ~]# date +%f2008-08-08 [Email protected] ~]# date-s "+1 Year" Sat
-U,--UTC,--universal output or set UTC time
--HELP Display command Help
--version Output Version Information
Format:
Format |
Description |
Instance |
%a |
Abbreviated Week name |
Thu |
%A |
Full Week name |
Thursday |
%b |
Abbreviated month name |
The |
%B |
Full month name |
August |
%c |
Date and time |
Thu 23 14:55:02 2001 |
%c |
Year/100 [00,99] |
20 |
%d |
The day ordinal of a month in decimal [01,31] |
16 |
%d |
Month/day/year [m%/d%/y%] |
06/16/12 |
%e |
The day ordinal of a month in decimal, plus a space before a number [1,31] |
10 |
%F |
Year-month-day [y%-m%-d%] |
2012-06-16 Common |
%g |
ISO 8601 uses the latter two digits of the week-based year |
12 |
%G |
ISO 8601 uses week-based years |
2012 |
%h |
Abbreviated month name, same as%b |
The |
%H |
24-Hour hour [00,23] |
14 |
%I |
12-hour hour [01,12] |
02 |
%j |
Day ordinal of the year [001,366] |
235 |
%k |
24-Hour hour [0,23] |
5 |
%l |
12-hour hour [1,12] |
5 |
%m |
Decimal month [01,12] |
08 |
%M |
minutes [00,59] |
55 |
%n |
Line break |
|
%N |
One-zero sec, nanosecond [000000000,999999999] |
000000001 |
%p |
am/pm |
Pm |
%P |
am/pm |
Pm |
%r |
local time: (12 o'clock System) |
11:01:23 AM |
%R |
Same as "%h:%m" |
11:01 |
%s |
Number of seconds from ' 00:00:00 1970-01-01 UTC ' |
1339819819 |
%s |
seconds [00,60] |
02 |
%t |
Horizontal tab |
|
%T |
Same as "%h:%m:%s" |
11:01:23 Common |
%u |
ISO 8601 Week, Monday for 1,[1,7] |
2 |
%u |
Week number, starting from Sunday [00,53] |
33 |
%V |
ISO 8,601 number of weeks [01,53] |
07 |
%w |
Week, Sunday for 0. [0,6] |
4 |
%W |
Week number, starting from Monday [00,53] |
34 |
%x |
Standard Date |
06/16/12 |
%x |
Standard Time |
14:55:02 |
%y |
After two digits of the year [00,99] |
12 |
%Y |
Years |
2012 |
%z |
UTC offset in ISO 8601 format |
-0500 |
%Z |
Time Zone Name |
Est |
%% |
Percent Sign |
% |
Part of the content is transferred from: HTTP://WWW.CNBLOGS.COM/WANGKANGLUO1/ARCHIVE/2012/11/20/2778554.HTML#BBB
Linux Date Command detailed