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:
-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 hours (00-23)
%I Hours (00-12)
%j date of 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 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)
%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.
Please report a date error to [email protected]
GNU coreutils Project Home:GNU Software general help:Please report a translation error of date to To get the complete document, run: info coreutils ' date invocation '
The current log of the Prophet in YYMMDD format
[[Email protected] ~]# Date ' +%y%m%d '
[[Email protected] ~]# Date "+%y_%m_%d"
Tar compress package with current datetime command
[[email protected] ~]# Touch 1.test
[[Email protected] ~]# tar zcfv ' date ' +%y%m%d ' _test.tar.gz 1.test
[[email protected] ~]# ls
[[Email protected] ~]# tar zcfv ' date ' +%f ' test.tar.gz 1.test
[[email protected] ~]# ls
1.test 2014-05-14test.tar.gz 20140514_test.tar.gz
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
: 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.
Because the date and time are important, this may be the reason for developing the Network Time Protocol (ntp:network times Protocol). Let's see how the following date command works.
Show system date
To display the system date, simply enter:
$ datethu DEC 5 22:55:41 WIB 2013
Format Display Date
Dates are available in many formats. If you don't like the default format, you can change the format. You might think, "Why do I need to change the format?" The default output is enough for me. "
Yes, you're right, but when you're programming, the default output might not meet your needs, so you need some custom output.
Date and time output format for RFC 2822
$ Date-rthu, 2013 23:40:53 +0700
RFC 2822 format like this: week, day-month-year, hour: minute: seconds time zone
Time zone +0700 is equivalent to GMT +7.
By default, date is used to define the time zone in /etc/localtime . Valid time zone data is defined in /usr/share/timezones.
Show or set the Coordinated universal
On Wikipedia, UTC means
The world's main clock and time standard. This is one of several very similar alternatives to Green's location standard time.
Displays the date and time in UTC, using the-u parameter
$ date-uthu Dec 5 16:45:58:UTC 2013
Using formatting options
To customize your date format, use the plus sign (+)
$ date + "Day:%d Month:%m year:%Y" day:05 month:12 year:2013
$ date +%D12/05/13
The %d format is the format of the year/month/day .
If you want, you can export the name of the date. Here are some examples:
$ date + "%a%b%d%y" Fri Dec 2013$ date + "%a%b%d%y" Friday December 2013$ date + "%a%b%d%y%T" Friday December 06 00:30:37$ Date + "%A%b-%d-%y%c" Friday december-06-2013 12:30:37 AM WIB
There are also a number of date formats. Just enter:
$ man Date
To display the syntax and parameters of the date command.
Basically, the date command translates all the contents of the format and output in quotation marks ("") at the beginning of all percent signs (%).
Set the system date and time
Usually, you want your system date and time to be set automatically. If for some reason you want to manually modify it, we can use this command.
# date–set= "20140125 09:17:00"
This will set your current system date and time to January, and 09:17:00 AM. Please note that you must have root privileges to do so. Otherwise you will get such a mistake.
Date:cannot set Date:operation not PERMITTEDSAT Jan 09:17:00 WIB 2014
Reset your time
If you want to reset your system date and time to the original value, you can use this technique.
# Hwclockfri Dec 03:44:10 AM WIB-0.314082 seconds
This sets your system date and time to what the output of the Hwclock command looks like.
Using the date command in a script
Remember when I said before why do you need to change the output of date? One answer is that you may need to program. Let's look at an example under the bash script.
$ VI display.date#! /bin/bashdatetime=$ (date + "Date:%a%b-%d-%y time:%T WEEK number:%W") echo $DATETIME
Save and run it:
$./display.datedate:fri dec-06-2013 time:03:08:19 WEEK number:40
If you find permission to reject the error message, enter:
$ chmod 755 display.date
Using date in the backup process
Another example is a child that uses date in your backup process.
$ date +%f2013-12-06$ tar zcfv/daily_backup/backup-' date +%f '. tar.gz/home/pungki/documents
It compresses the folder /home/pungki/documents to a file backup-2013-12-06.tar.gz in /daily_backup folder. "Command" to embed other commands in the command line, this character is not a single quotation mark, but the same as the wave number ~ the same keyed symbol. ）
Date may be considered unimportant in some respects. But date has played an important role. To know more details about the date command, enter man date to access the man page under your console.
This article from "the more efforts, the more fortunate!" "Blog, be sure to keep this provenance http://7250365.blog.51cto.com/7240365/1410788