Date of the Linux command

Source: Internet
Author: User

Example: Use the date command to output the "XXXX-XX-XX" format, such as 2015-03-01.

#date +%y-%m-%d 2015-03-0#date +%f2015-02-28

The 1.date command enables a variety of format outputs, depending on the connection symbol between the representation symbols (such as%y):

# Date +%y/%m/%d2015/02/28# Date +%h:%m00:54

2.date Command main options:

-D: When using man date to view the-D option description is ambiguous, (-D,--date=string display time described by STRING, not ' now '), the actual use of-D indicates the past, the future:

# date-d Next-day +%y-%m-%d #明天日期2015 -03-01 # date-d last-day +%y-%m-%d #昨天日期2015-02-27

A simpler approach is to take +nday or-nday,n as numbers after-D, such as +3day after 3 days, and use +nhour,-nhour, minutes, +nmin,-nmin for the same hour.

# date-d +3daysat Mar 7 16:10:37 CST 2015

3.date command time character indication:

in terms of time :

%: Print out

%n: Next line

%t: Jump Grid

%H: hours

%I: hours

%k: hours 1

%l: hours 1

%M: min .

%p: show local AM or pm (morning, afternoon)

%r: Direct display time ( in the form of Hh:mm:ss [ap]m)

%s: number of seconds from 1970 year 1 month 1 00:00:00utc to date

%s: seconds

%T: Direct display time ( 01:18:50-hour system)

%x: Time display 01:19 09 seconds

%Z: display time zone CST


Date Aspects :

%a: Day of the Week (SUN,SAT)

%A: Day of the Week (sunday,saturday)

%b: month (JAN,DEC)

%B: month (january,december)

%c: Show Date and time directly (Sat 01:22:34)

%d: Day (31)

%d: Show date directly (MM/DD/YY)

%h: with %b

%j: The first day of the Year (001,366)

%m: month, with number (01,12)

%u: Week of the Year (00,53) ( in Sunday as the first day of the week )

%w: week, expressed as a number (6)

%W: Week of the Year (00,53) ( with Monday as the first day of the week )

%x: Show date directly (MM/DD/YY)

%y: last two digits of the year (00,99)

%Y: full year (0000,9999)


4. Modification time

If you do not start with a plus sign, you want to set the time, and the time format is MMDDHHMM[[CC]YY][SS],

which MM is the month,

DD is the day,

HH for hours,

MM for minutes,

CC is the first two digits of the year,

YY is two digits after the year,

SS is the number of seconds

# date 03041605Wed Mar 4 16:05:00 CST 2015


Use Date–s: Modify Time by string
You can only modify the date and not modify the time:

Date-s 2015-03-04wed Mar 4 00:00:00 CST 2015

Modify time only:

# date-s 16:20:00wed Mar 4 16:20:00 CST 2015

Also modify the date time, note to add double quotation marks, the date and time there is a space between, enter:

# date-s "2015-03-04 16:22:00" Wed Mar 4 16:22:00 CST 2015

Other instructions:

when you don't want to appear meaningless0when(For Example2005/03/01), you can insert it in the tag - symbols, such asDate +%-h:%-m:%-swill make no sense in time and seconds0to be removed, like the original.01:09:04will become1:9:4.

In addition, only those who obtain permission ( e.g. root) to set the system time. When you Change the system time as root, remember to use clock-w to write the system time to the CMOS , The system time will continue to hold the latest correct value on the next reboot.  



This article is from the "Sweetsmile" blog, make sure to keep this source http://daizhancheng.blog.51cto.com/9708457/1617270

Date of the Linux 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.