Detailed Date command

Source: Internet
Author: User
Tags rfc

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]]

    • Show Current Time

#显示当前日期, 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

    • Displays the date of the specified string description

#显示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

    • Setting the system time

# "" 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

    • Read the date row by line from the file

#以下是文件中的内容

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

    • Displays the last modified time of the file

[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

    • Other uses

#以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

    • Common date formats

#显示当前时间的年份, + 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.