The Linux date command is used in linux shell programming. Before the date addition and subtraction operations are often used, they are calculated by using the expr function. In fact, the date command itself provides the date addition and subtraction operation very conveniently. 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 www.2cto.com % t: Hop size % 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. For the set time, www.2cto.com date-s // sets the current 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 by eggplant _ 2008