Answers:
如果您使用的是Bash,则还可以使用以下命令之一:
printf '%(%Y%m%d%H%M%S)T'       # prints the current time
printf '%(%Y%m%d%H%M%S)T' -1    # same as above
printf '%(%Y%m%d%H%M%S)T' -2    # prints the time the shell was invoked
您可以使用Option -v varname存储结果,$varname而不是将其打印到stdout:
printf -v varname '%(%Y%m%d%H%M%S)T'尽管date命令将始终在子shell中执行(即在单独的进程中),但printf是内置命令,因此会更快。
%可以传递哪些选项的进一步文档的任何人,这似乎都在使用该date命令。因此,man date将为您提供可用的选项。
                    没有标点符号(如@Burusothman提到的):
current_date_time="`date +%Y%m%d%H%M%S`";
echo $current_date_time;
O / P:
20170115072120带标点符号:
current_date_time="`date "+%Y-%m-%d %H:%M:%S"`";
echo $current_date_time;
O / P:
2017-01-15 07:25:33
"`date +%Y-%m-%d %H:%M:%S`"给我一个date: illegal time format