1. Display time
The date command displays dates in the specified format, and only date displays the current time in the default format. As follows:
If you need to display the date in the specified format, you can use a string that begins with "+" to specify its format, in the following format:
%n: Next line
%t: Jump Grid
%H: Hours (00-23)
%I: Hours (01-12)
%k: Hours (0-23)
%l: Hours (1-12)
%M: minutes (00-59)
%p: Show local AM or PM
%r: Direct Display time (12-hour format, HH:MM:SS [ap]m)
%s: Number of seconds from January 1, 1970 00:00:00 UTC to date
%s: Seconds (00-60)
%T: Direct Display time (24-hour system)
%x: Equivalent to%h:%m:%s
%Z: Show 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: The first day of the Year (001-366)
%m: Month (01-12)
%u: Week of the Year (00-53) (Sunday is the first day of the week)
%w: Day of the Week (0-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)
These formats do not have to be remembered, only a few common ones. For example,%y represents the year,%m for the month,%d for the day,%h for the hour,%m for minutes,%s for seconds, and%s for the number of seconds from January 1, 1970 to 00:00:00 UTC, equivalent to the time function, and%w represents the day of the week.
See the example below:
If the time to display is not the current time, but the elapsed time, you can use the-D option. For example, show time three years ago:
See this command I was very hurt, the past time can no longer go back, can only use the command to see. Displays the time after three months:
Show time after 10 days:
Sometimes you need to get the number of seconds that the current time is away from 1970 0:0 0 seconds, stored in the variable:
2. Set the time
Use the-S option to set the system time:
There are a variety of ways to choose from:
You need to believe in the intelligence of date enough.
More places to use:
Use the date command to get the current date and create a new folder based on that date.
Usage of the Linux Date command (GO)