The date command displays or sets the system time and date
Grammar
date [options] [parameters]
Options
-D < string;: displays the time or date specified by the string. double quotation marks before and after strings
-S < string;: sets the time or date specified by the string. double quotation marks before and after strings
Parameters
%H: Hours, 24-hour (00-23)
%I: Hours, 12-hour (01-12)
%M: minutes (00-59)
%s: Seconds (00-59)
%p: Show AM or PM
%s: from January 1, 1970 00:00:00 to the number of seconds currently experienced
%F: Show Date (%y-%m-%d)
%Y: Display year (4 bits, e.g. 2016)
%y: Display year (2 for, for example 2016 16)
%m: Month
%d: Day
%x: Format of the display time (%h:%m:%s)
%T: Display time, 24-hour system (HH:MM:SS)
Practice
[[Email protected] ~]# Date July 17, 2016 Sunday 21:02:53 Cst[[email protected] ~]# date +%f2016-07-17[[email protected] ~]# Date + "%F%T" 2016-07-17 21:04:15
-D to specify day month, respectively. Same as below command format
[Email protected] ~]# date-d "-1 month" +%f #显示上一个月的日期2016 -06-17[[email protected] ~]# date-d "+1 month" +%f #显示下 One-month date 2016-08-17
-S sets the current time. (only root permissions can be set, other users can only view)
[Email protected] ~]# date-s 2016-07-16 #这样设置日期会将具体时间设置为00 -00-00[[email protected] ~]# date-s 16:10:30 #只设定具体时间 , the date will not move [[email protected] ~]# date-s "20150505 21:10:01" #设置全部时间
Detailed Date command