diff --git a/command/date.md b/command/date.md index 27b7e5d9b3..a182904c6c 100644 --- a/command/date.md +++ b/command/date.md @@ -152,5 +152,19 @@ difference=$(( end - start )) echo $difference seconds. ``` +当你考虑输出带有时间的字符串时,例如(Current time: 2019/05/19): + +最常用的方法: + +```shell +echo -e "Current time: $(date +"%Y%m%d")" +``` + +另一种方法: +```shell +suffix='Current time:' +#和echo的用法差不多,注意如果换成单引号就不能替换变量了。 +date +"${suffix} %Y/%m/%d" +```