If you use Bash, you can also use one of the following commands:
printf '%(%Y%m%d%H%M%S)T'
You can use the -v varname option to save the result to $varname instead of printing it to stdout:
printf -v varname '%(%Y%m%d%H%M%S)T'
While the date command will always be executed in a subshell (i.e., in a separate process), printf is a built-in command and therefore will be faster.
afaller May 16 '17 at 15:08 2017-05-16 15:08
source share