Command: Date [options]
In Linux shell programming, the addition and subtraction of dates is often used
I used to use the expr function to calculate the problem.
Actually, the date command itself provides the addition and subtraction of dates.
Very convenient. For example: Get yesterday's time
Date +%y%m%d--date= "-1 day"
Date Usage: date [OPTION] ... [+format] The
Date [-u|--utc|--universal] [MMDDHHMM[[CC]YY][.SS]]
Date can be used to display or set the date and time of the system.
1. In the display, the user can set the format to be displayed, formatted as a plus followed by a number of tokens, where the list of available tokens is as follows:%: print out%
%n: Next line
%t: Jump grid
% H: Hours (00..23)
%I: Small Time (01..12)
%k: Hours (0..23)
% L: Hours (1..12)
% M: minutes (00..59)
%p: Show local AM or PM
%r: Direct display times (12-hour format, HH:MM:SS [AP] M)
%s: The number of seconds since January 1, 1970 00:00:00 UTC
% s: seconds (00..61)
% T: Direct display time (24 hour)
% X: equivalent to%h:%m:%s
%Z: Explicit Time zone%a: Day of the Week (Sun. Sat)
% A: Day of the Week (Sunday). Saturday)
%b: Month (Jan). DEC)
% B: Month (January). December)
%c: Display date and time directly
%d: Day (01..31)
% d: Show date directly (MM/DD/YY)
%h: With%b
%j: Day of the Year (001..366)
%m: Month Copy (01..12)
% U: Week of the Year (00..53) (with Sunday as the first day of the week)
%w: Day of the Week (0..6)
% W: Week of the Year (00..53) (Monday is the first week of Days)
%x: Display date directly (MM/DD/YY)
%y: Last two digits of the year (00.99)
% y: Full year (0000..9999)
2. In terms of setting time
Date-s//Set current time, only root privileges can be set, others can only be viewed.
Date-s 20080523//set to 20080523, this will set the specific time to empty 00:00:00
Date-s 01:01:01//Set time, no changes made to date
Date-s "01:01:01 2008-05-23″//so you can set the whole time
Date-s "01:01:01 20080523″//so you can set the whole time
Date-s "2008-05-23 01:01:01″//so you can set the whole time
Date-s "20080523 01:01:01″//so you can set the whole time
3. Add and Subtract
Date +%y%m%d//display now day and Month day
Date +%y%m%d--date= "+1 Day"//Display days later
Date +%y%m%d--date= "-1 days"//Displays the day before
Date +%y%m%d--date= "-1 month"//show dates on January
Date +%y%m%d--date= "+1 Month"//displays the dates for the next January
Date +%y%m%d--date= "-1 Year"//show dates for previous years
Date +%y%m%d--date= "+1 Year"//show dates for next
or simpler point of date= ' date-d-${t}day ' +%y%m%d '//For T for the first few days
linux-Command-date