time=$(date “+%Y%m%d-%H%M%S”)
or
time=$(date “+%Y-%m-%d %H:%M:%S”)
……
in any format you want
echo “${time}”
the above two lines of simple code is that the shell takes the current time and outputs it in the format it wants.
a couple of things to note
- date is followed by a space, otherwise the command cannot be recognized, the shell is very strict with the space.
- Y shows 4-digit years, such as: 2018; Y displays a 2-digit year, such as: 18. M is for month; M is for minutes. D represents the day, and D represents the current date, i.e. 1/18/18(i.e. 2018.1.18). H represents hours, and H shows months (somewhat muddled). S displays the current second in milliseconds; S displays the current second in seconds.
Read More:
- The shell gets the current time of the system and formats it
- Common shell (1): shell gets the current time stamp of the system
- How to get the current time in java time string
- Gradle:Using flatDir should be avoided because it doesn‘t support any meta-data formats.
- Linux view current date and time
- Set the default time to the current value in MySQL
- MySQL will delete the data minutes before the current time
- In SQLite database, set the default value for the field as the current time
- When a system is deployed on weblogic12.2.1.3, it reports an error “IllegalStateException zip file closed”. When it is deployed on weblogic12.2.1.2, it does not report an error and can be accessed normally.
- When SAP receives the goods, the system prompts that it can only be recorded in the period 2009 / 09 and 2009 / 08 of company code 1101
- When xshell 6 is connected normally for the first time, it will prompt could not connect to ‘127.0.0.1’ (port 61708): connection failed
- An undetermined call to function ‘shell’: missing ‘. Stop. Problem encountered when using shell command in makefile
- Time, strftime and strptime in Python
- The time of the time database displayed by the front end is inconsistent
- Vscode automatically formats the code when an error is reported
- Reading and display of various image formats in VTK
- After switching the tidb database, an error could not commit JDBC transaction appears from time to time
- Abnormal reading after stm32f4 RTC time setting
- You set the variable “no_check_targets“ here and it was unused before it went out of scope.
- When calling time module – time / datetime in wxPython, an error is reported. Valueerror: unknown locale: zh cn