time=$(date “+%Y%m%d-%H%M%S”)
or
time=$(date “+%Y-%m-%d %H:%M:%S”)
… and other formats you want
echo “${time}”
The above two lines of simple code are shell to get the current time and output it in the format you want.
Several points need to be noted
There is a space after
- date, otherwise the command cannot be recognized, and the shell is very strict on spaces. Y shows 4-digit year, such as 2018; y shows 2-digit year, such as 18. M is the month; m is the minute. D is the day, and D is the current date, such as 1 / 18 / 18 (2018.1.18). H is the hour and H is the month. S displays the current second in milliseconds; s displays the current second in seconds.
Read More:
- 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
- MySQL will delete the data minutes before the current time
- Set the default time to the current value in MySQL
- 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
- Vscode automatically formats the code when an error is reported
- Reading and display of various image formats in VTK
- The time of the time database displayed by the front end is inconsistent
- Time, strftime and strptime in Python
- After switching the tidb database, an error could not commit JDBC transaction appears from time to time
- Abnormal reading after stm32f4 RTC time setting
- Register global time filter in main.js in Vue
- When calling time module – time / datetime in wxPython, an error is reported. Valueerror: unknown locale: zh cn