The shell gets the current time of the system and formats it

time=$(date “+%Y%m%d-%H%M%S”)


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: