Help information for the date command
[root@localhost 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
For 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:
-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)
date and time of the current locale of%c (e.g. Thursday, March 3, 2005 23:05:25)
%c century; for example,%Y, typically omitting the last two digits of the current year (for example:
%d date by month (ex: $)
%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)
%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 the Week (00-53)
Date Description Under the current locale of%x (for example: 12/31/99)
time description under the current locale of%x (for example: 23:13:48)
%y Year last two digits (00-99)
%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.
Date is a system command that comes with the Linux system to display the current system time, but the default display contains a lot of information, especially when it is exported as a file name, not very convenient.
Fortunately, the date command contains the option to format the output
[[Email protected] ~]# date "+%y-%m-%d" 2013-02-19[[email protected] ~]# date "+%h:%m:%s" 13:13:59[[email protected] ~]# da TE "+%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 Pro Tected] ~]# date-d todaytue Feb 13:10:38 CST 2013[[email protected] ~]# date-d nowtue Feb 13:10:43 CST 2013[[email Protected] ~]# date-d tomorrowwed Feb 13:11:06 CST 2013[[email protected] ~]# date-d yesterdaymon Feb 13:11:58 CS T 2013
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 the system time, 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.
This command forces the system time to be written to the CMOS.
Linux under date command, format output, time settings