Linux (2) Date command

Source: Internet
Author: User
Tags iso 8601 iso 8601 format local time month name time and date

Feature Description: Displays or sets the system time and date.

Syntax: Date

[-D < string;]

[-u]

[+%h%i%k%l%m%p%r%s%s%t%x%z%a%a%b%b%c%d%d%j%m%u%w%x%y%y%n%t] or

Date [-S < string >][-u] [Mmddhhmmccyyss] or date [--help][--version]

Supplemental NOTE: The first syntax can be used to display the system date or time, the parameter that begins with% is the format parameter, and you can specify the display format for the date or time. The second syntax can be used to set the system date
and time. Only administrators have permission to set the date and time. If you do not add any parameters, data displays the current date and time.

Parameter:
%H hours, expressed as 00-23.  
%I Hours (expressed in 01-12).
%K hours (expressed as 0-23).
%l hours (expressed as 0-12).
%M minutes (expressed as 00-59).
%P am or PM. The
%r time, in minutes and seconds, and hours in 12-hour am/pm.
The total number of seconds in%s. The starting time is 1970-01-01 00:00:00 UTC.
%s seconds (as represented by local idioms).
%T time (minutes and seconds, hours in 24-hour notation). The
%x time, expressed in local idiomatic notation.
%Z downtown.
The abbreviation for%a week. The full name of the
%A week.
The abbreviation for the English name of the%b month.
The full English name of the%B month.
%c Date and time. Entering only the date instruction will also show the same result. The
%d date (represented by 01-31).  
%d Date (including month date).
%j the day ordinal of the year. The
%m month (represented by 01-12).
%u the number of weeks in the year.
%w The number of days of the week, 0 for Sunday, 1 for Monday, once analogy. The
%x date (represented by local idiom). The
%y year (represented by 00-99). The
%Y year, expressed as a four-digit number.
%n Inserts a new line when it is displayed.
%t when displayed, Insert tab.
MM Month (required).
DD Date (required).
HH Hour (necessary).
mm minutes (required). The first two digits of the
CC year (optional).
The latter two digits of the YY year (optional).
SS seconds (selectivity).
-d< String > Displays the date and time that the string refers to. Double quotation marks must be added before and after strings. The
-s< string > Sets the date and time based on the string. Double quotation marks must be added before and after strings.
-U displays GMT.
--help online Help. The
--version displays the version information.

Format

Description

Instance

%a

Abbreviated Week name

Thu

%A

Full Week name

Thursday

%b

Abbreviated month name

The

%B

Full month name

August

%c

Date and time

Thu 23 14:55:02 2001

%c

Year/100 [00,99]

20

%d

The day ordinal of a month in decimal [01,31]

16

%d

Month/day/year [m%/d%/y%]

06/16/12

%e

The day ordinal of a month in decimal, plus a space before a number [1,31]

10

%F

Year-month-day [y%-m%-d%]

2012-06-16

%g

ISO 8601 uses the latter two digits of the week-based year

12

%G

ISO 8601 uses week-based years

2012

%h

Abbreviated month name, same as%b

The

%H

24-Hour hour [00,23]

14

%I

12-hour hour [01,12]

02

%j

Day ordinal of the year [001,366]

235

%k

24-Hour hour [0,23]

5

%l

12-hour hour [1,12]

5

%m

Decimal month [01,12]

08

%M

minutes [00,59]

55

%n

Line break

%N

One-zero sec, nanosecond [000000000,999999999]

000000001

%p

am/pm

Pm

%P

am/pm

Pm

%r

local time: (12 o'clock System)

11:01:23 AM

%R

Same as "%h:%m"

11:01

%s

Number of seconds from ' 00:00:00 1970-01-01 UTC '

1339819819

%s

seconds [00,60]

02

%t

Horizontal tab

%T

Same as "%h:%m:%s"

11:01:23

%u

ISO 8601 Week, Monday for 1,[1,7]

2

%u

Week number, starting from Sunday [00,53]

33

%V

ISO 8,601 number of weeks [01,53]

07

%w

Week, Sunday for 0. [0,6]

4

%W

Week number, starting from Monday [00,53]

34

%x

Standard Date

06/16/12

%x

Standard Time

14:55:02

%y

After two digits of the year [00,99]

12

%Y

Years

2012

%z

UTC offset in ISO 8601 format

-0500

%Z

Time Zone Name

Est

%%

Percent Sign

%

Reprint--

[[Email protected] ~]# Date
September 08, 2015 Tuesday 11:28:03 CST

[Email protected] ~]# date +%y-%m-%d-%h:%m
2015-09-08-11:32

Here are some experiments done to make it easier to understand

Reprint: http://www.cnblogs.com/xuxm2007/archive/2010/12/07/1899045.html
01020304050607080910111213141516171819202122232425262728293031323334353637383940414243444546474849 $ date -d "2010-11-15 23:00:01"Mon Nov 15 23:00:01 PST 2010$ date -d "2010/11/15 23:0:2"Mon Nov 15 23:00:02 PST 2010$ date -d "2010/11/15T23:0:2"Mon Nov 15 08:00:02 PST 2010$$ echo "2010-11-15 23:00:01" > date.txt$ echo "2010/11/15 23:00:02" >> date.txt$ cat date.txt2010-11-15 23:00:012010/11/15 23:00:02$ date -f date.txtMon Nov 15 23:00:01 PST 2010Mon Nov 15 23:00:02 PST 2010$$ ls -ltotal 4-rw-r--r-- 1 znan sybase    40 Nov 15 21:14 date.txt$ date -r date.txtMon Nov 15 21:14:36 PST 2010$$ date -I2010-11-15$ date -Ihours2010-11-15T21-0800$ date -Iminutes2010-11-15T21:16-0800$ date -Iseconds2010-11-15T21:16:24-0800$$ date -RMon, 15 Nov 2010 21:47:08 -0800$ date -uTue Nov 16 05:47:13 UTC 2010$$ date +"Today is %A."Today is Monday.$ date +"Date:%b. %e, %G"Date:Nov. 15, 2010$ date +"Date: %b.%e, %G"Date: Nov.15, 2010$ date +"%x %X"11/15/2010 09:50:21 PM$ date +"%Y-%m-%d %H:%M:%S"2010-11-15 21:51:32$ date +"%Y-%m-%d %I:%M:%S %p"2010-11-15 09:51:55 PM$

Linux (2) Date command

Related Article

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.