shell中的时间日期获取

cat test5:

#!/bin/bash
# using the backtick character
testing=`date`
echo "The date and time are:" $testing
date=`date +%Y-%m-%d_%H-%M-%S`
echo "The date are:" $date

添加可执行权限:chmod u+x test5

运行:./test5 结果如下:

The date and time are: Thu Jan  :: CST
The date are: --22_15--
05-21 16:37