The date command displays dates or sets the system date using the specified format.
Command format:
Date [Options] ... [+ format]
Or: Date [-u|--utc|--universal] [MMDDHHMM[[CC]YY][.SS]]
#显示当前日期, my Linux installation is using the Chinese encoding, so the display is Chinese
[Root@localhost ~] #date
Sunday, October 04, 2015 01:38:07 CST
#以指定格式显示当前日期的小时, the date format is shown in the following section of the article, showing only know +%h for hours
[root@localhost ~] #date +%h
01
#显示2015-05-25 Represents the date
[Root@localhost ~]# date-d 2014-05-02
Friday, May 02, 2014 00:00:00 CST
[Root@localhost ~]# Date--date=2015-05-25
Monday, May 25, 2015 00:00:00 CST
# "" means space character,-S 2015-10-03 "" 18:17:00 set 2015-10-03 18:17:00 for system time
#使用 +%y-%m-%d% ""%h:%m:%s specifies the date format for the 2015-10-03 18:17:00
[Root@localhost ~]# date-s 2015-10-03 "" 18:17:00 +%y-%m-%d% ""%h:%m:%s
2015-10-03% 18:17:00
#使用长命令方式设置
[[Email protected] ~]# date--set=2015-10-03 "" 18:17:00 +%y-%m-%d% ""%h:%m:%s
2015-10-03% 18:17:00
#以下是文件中的内容
2015-10-03 18:17:00
2015-10-03 18:19:00
2015-10-03 18:20:00
#逐行读取日期字符串并输出
[Email protected] ~]# date-f test
Saturday, October 03, 2015 18:17:00 CST
Saturday, October 03, 2015 18:19:00 CST
Saturday, October 03, 2015 18:20:00 CST
[Email protected] ~]# date--file=test
Saturday, October 03, 2015 18:17:00 CST
Saturday, October 03, 2015 18:19:00 CST
Saturday, October 03, 2015 18:20:00 CST
[Email protected] ~]# date-r test
Saturday, October 03, 2015 19:40:38 CST
[Email protected] ~]# date--reference=test
Saturday, October 03, 2015 19:40:38 CST
#以RFC 2822 Format output date and time
[Email protected] ~]# date-r
Sat, OCT 2015 20:44:49 +0800
[Email protected] ~]# date--rfc-2822
Sat, OCT 2015 20:45:14 +0800
#以RFC 3339 Format output date and time
#TIMESPEC = ' Date ', ' seconds ', or ' ns '
#表示日期和时间的显示精度.
#日期和时间单元由单个的空格分开:
[Email protected] ~]# date--rfc-3339=date
2015-10-03
[Email protected] ~]# date--rfc-3339=seconds
2015-10-03 20:49:17+08:00
[Email protected] ~]# date--rfc-3339=ns
2015-10-03 20:49:22.762993721+08:00
#设置或输出协调通用时间
[Email protected] ~]# Date-u
Saturday, October 03, 2015 12:51:59 UTC
#显示帮助信息
[Email protected] ~]# date--help
#显示版本信息
[Email protected] ~]# date--version
#显示当前时间的年份, + indicates that this is a date format,% is a fixed format, Y represents the four-digit year of the fetch date, and Y represents the post two-digit year
[Email protected] ~]# date +%y
2015
[Email protected] ~]# date +%y
15
#显示指定字符串表示的时间的月份 (01-12)
[Email protected] ~]# date-d 2015-05-20 +%m
05
#显示指定字符串表示的时间的日期
[Email protected] ~]# date-d 2015-05-01 +%d
01
#显示指定字符串表示的时间的日期, leading petty space padding
[Email protected] ~]# date-d 2015-05-01 +%_d
1
#完整日期格式, equivalent to%y-%m-%d
[Email protected] ~]# date-d 2015-05-01 +%f
2015-05-01
#显示小时 (0-23)
[Email protected] ~]# date-d 2015-05-01 "" 13:25:00 +%k
13
#显示小时 (1-12)
[Email protected] ~]# date-d 2015-05-01 "" 13:25:00 +%l
1
#显示小时 (00-23)
[Email protected] ~]# date-d 2015-05-01 "" 13:25:00 +%h
13
#显示小时 (00-12)
[Email protected] ~]# date-d 2015-05-01 "" 13:25:00 +%i
01
#显示分钟 (00-59)
[Email protected] ~]# date-d 2015-05-01 "" 13:25:00 +%m
25
#显示秒 (00-60)
[Email protected] ~]# date-d 2015-05-01 "" 13:25:00 +%s
00
Other formats can be viewed using--HELP.
Detailed Date command