About date in linux Command Learning

Source: Internet
Author: User

In linux, the date command is used to display and set the system date and time. On a linux server, you can use man date to view the usage of date. In the date setting time format command, each option has the following meanings:-d datestr, -- date datestr: displays the date-s datestr described by datestr, -- set datestr sets the date 1 described by datestr, and % n: Next row % t: Hop grid % H: hour (00 .. 23) % I: hour (01 .. 12) % k: hour (0 .. 23) % l: hour (1 .. 12) % M: minute (00 .. 59) % p: Local AM or PM % r: direct display time (in 12-hour format: hh: mm: ss [AP] M) % s: seconds from January 1, 1970 00:00:00 UTC till now % S: seconds (00 .. 61) % T: direct display time (in 24-hour format) % X: equivalent to % H: % M: % S % Z: Display Time Zone % A: The day of the week (Sun .. sat) % A: The day of the week (Sunday .. saturday) % B: Month (Jan .. dec) % B: Month (January .. december) % c: Display date and time % d: Day (01 .. 31) % D: Display date (mm/dd/yy) % h: Same as % B % j: day of the year (001 .. 366) % m: Month (01 .. 12) % U: Week (00 .. 53) (Sunday is the first day of a week) % w: The day of a week (0 .. 6) % W: Week (00 .. 53) (Monday is the first day of a week) % x: displays the date (mm/dd/yy) % y: the last two digits of the Year (00.99) % Y: full Year (0000 .. 9999) 2. date-s // set the current time in terms of the set time. Only the root permission can be set. Settings, others can only be viewed. Date-s 20080523 // set to 20080523, so that the specific time is set to null 00: 00: 00 date-s 01:01:01 // set the specific time, do not change the date-s "01:01:01" // you can set the full time date-s "01:01:01 20080523" // you can set the full time date-s "01:01:01 ″ // you can set the full time date-s "20080523 01:01:01" // you can set the full time 3. date calculation date + % Y % m % d // display the date of the day before yesterday + % Y % m % d -- date = "+ 1 day" // display the date of the previous day + % Y % m % d -- date = "-1 day" // display date + % Y % m % d -- date = "-1 month" // display date + % Y % m % d -- date = "+ 1 month "// display the date of the next month + % Y % m % d -- date ="-1 year "// display the date of the previous year + % Y % m % d -- date = "+ 1 year" // display the date of the next year. 4. Example: in a linux environment, to obtain the period a few days ago, you only need to use date-d "x days ago" + % Y % m % dx instead of a number. If you need to directly write a positive number a few days ago, if you want to directly write a negative number to the date after a few days, replace date-d "x weeks ago" + % Y % m % dx with a number. If you need to write a positive number directly a few weeks ago, if you want to write a negative number for the date after a few weeks, replace date-d "x years ago" + % Y % m % dx with a number. If you want to write a positive number directly a few years ago, if it takes a few years, write a negative number directly on the date;

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.