Date-print or set the system date and time
Display the current time in the given FORMAT, or set the system date.
Function: Displays the current time in the given format, or sets the system date.
Syntax: Date [OPTION] ... [+format]
Parameters:-d< string;: Displays the date and time that the string refers to. Double quotation marks must be added before and after strings;
-s< string;: Sets the date and time according to the string. Double quotation marks must be added before and after strings;
Format string:
%H hours, 24-hour (00~23)
%I Hours, 12-hour (01~12)
%k hours, 24-hour (0~23)
%l hours, 12-hour (1~12)
%M min (00~59)
%p Show AM or PM
%r display time, 12-hour system (HH:MM:SS%p)
%s from January 1, 1970 00:00:00 to the number of seconds currently experienced
%s Display seconds (00~59)
%T display time, 24-hour system (HH:MM:SS)
%x shows the format of Time (%h:%m:%s)
%Z Display time zone, date field (CST)
%a week abbreviation (SUN~SAT)
Full name of%A week (Sunday~saturday)
%h,%b month abbreviation (JAN~DEC)
Full name of%B month (January~december)
%c Date and time (Tue Nov 20 14:12:58 2012)
%d the day of the one month (01~31)
%x,%d Date (MM/DD/YY)
%j the first day of the Year (001~366)
%m Month (01~12)
%w Day of the week one (0 for Sunday)
%W Week of the year (00~53, Monday for first day)
The last two digits of the%y year (1999 is 99)
Formatted output: Date + "%y-%m-%d" 2009-12-07
Output yesterday Date: date-d "1 day Ago" + "%y-%m-%d" 2012-11-19
2 seconds after output: date-d "2 Second" + "%y-%m-%d%h:%m.%s" 2012-11-20 14:21.31
Legendary 1,234,567,890 seconds: date-d "1970-01-01 1234567890 seconds" + "%y-%m-%d%h:%m:%s" 2009-02-13 23:02:30
Normal to format: date-d "2009-12-12" + "%y/%m/%d%h:%m.%s" 2009/12/12 00:00.00
Apache format conversion: date-d "Dec 5, 12:00:37 AM" + "%y-%m-%d%h:%m.%s" 2009-12-05 00:00.37
Format Conversion time walk: date-d "Dec 5, 12:00:37 AM 2 year ago" + "%y-%m-%d%h:%m.%s" 2007-12-05 00:00.37
Add and Subtract operations:
Date +%y%m%d//Display day of the day before date
Date-d "+1 Day" +%y%m%d//Displays the date of the previous
Date-d "-1 day" +%y%m%d//Display date
Date-d "-1 month" +%y%m%d//display date on January
Date-d "+1 Month" +%y%m%d//Show date for next January
Date-d "-1 Year" +%y%m%d//Displays the date of the previous one
Date-d "+1 Year" +%y%m%d//show the date of the next
Set time: Date-s//Set the current time, only root privileges can be set, others can only view
Date-s 20120523//set to 20120523, this will set the specific time to empty 00:00:00
Date-s 01:01:01//Set time, no changes made to date
Date-s "01:01:01 2012-05-23"//This can set the whole time
Date-s "01:01:01 20120523"//This can set the whole time
Date-s "2012-05-23 01:01:01"//This will set the whole time
Date-s "20120523 01:01:01"//This can be set all the time sometimes need to check a set of commands to spend time,
Example: #!/bin/bash start=$ (date +%s)
Nmap man.linuxde.net &>/dev/null end=$ (date +%s)
difference=$ ((End-start))
echo $difference seconds.
From: Http://man.linuxde.net/date
This article is from the "Little Bunny" blog, make sure to keep this source http://10551983.blog.51cto.com/10541983/1679303
Linux command Details--date