Linuxdate format time and date

Source: Internet
Author: User
Linuxdate format time and date [root @ brief test ~] Date-dtoday + & quot; % Y-% m-% d & quot; 2008-05-07 [root @ brief test ~] Date-dtoday + & quot; % Y _ %-m _ %-d & quot; 2008_5_7 [root @ brief test ~ Linux date formatting time and date [root @ 108 test ~] # Date-d today + "% Y-% m-% d" [root @ 108 test ~] # Date-d today + "% Y _ %-m _ %-d" 2008_5_7 [root @ 108 test ~] # Date-d today + "% Y-% m-% d % T" 14:55:19 [root @ 108 test ~] # Date-d today + "% Y-% m-% d % H: % M" 2008-05-07 [root @ 108 test ~] # Date-d today + "% Y-% m-% d % H: % M: % S" 14:55:57 in linux shell programming, the addition and subtraction operations of dates are often used by the expr function. In fact, the date command itself provides a very convenient addition and subtraction operation for date. For example, you can get the date + % Y % m % d -- date = "-1 day" date of the previous day. usage: date [OPTION]... [+ FORMAT] date [-u | -- utc | -- universal] [MMDDhhmm [[CC] YY] [. ss] date can be used to display or set the system date and time. 1. in terms of display, you can set the format to be displayed. the format is set to a plus sign followed by several tags. the available tag lists are as follows: %: print % n: next line % t: hop % 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: 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. 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. add or subtract date + % Y % m % d // Display date + % Y % m % d -- date = "+ 1 day" // Display date + % Y of the previous day % m % d -- date = "-1 day" // display the date of the next day + % Y % m % d -- date = "-1 month" // display the last month 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
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.