shell to achieve to get the current time, and format conversion method:
1) The output format
September 30, 2018 Sunday 15:55:15 CST
time1=$(date)
echo $time1
2) time series output
20180930155515
#!bin/bash
time2=$(date "+%Y%m%d%H%M%S")
echo $time2
3)2018-09-30 15:55:15
#!bin/bash
time3=$(date "+%Y-%m-%d %H:%M:%S")
echo $time3
4)2018.09.30
#!bin/bash
time4=$(date "+%Y.%m.%d")
echo $time4
note
1, there is a space behind the date, shell for demanding spaces
2, with no spaces before and after the variable assignment
3, explain
Y显示4位年份,如:2018;y显示2位年份,如:18。
m表示月份;M表示分钟。
d表示天;D则表示当前日期,如:1/18/18(也就是2018.1.18)。
H表示小时,而h显示月份。
s显示当前秒钟,单位为毫秒;S显示当前秒钟,单位为秒。