#!/bin/bash
# @author : wangjia_yql@qq.com
# @time : 2018/8/8 11:25
# @desc : 當前時間戳、日期顯示;時間戳轉日期、時間戳轉日期
# 顯示當前系統時區日期和時間戳: ./curr.sh
# 系統時區日期轉時間戳: ./curr.sh "2018-08-08 12:37:07
# 時間戳轉系統時區日期: ./curr.sh 1533703027
user_input=$1
if [ -z "${user_input}" ];
then
echo "now:"
date "+%Y-%m-%d %H:%M:%S"
date +%s
else
#用長度判斷用戶輸入是 時間戳還是格式化日期
if [ "${#user_input}" -lt 15 ];
then
date -j -f "%s" "${user_input}" "+%Y-%m-%d %H:%M:%S"
else
date -j -f "%Y-%m-%d %H:%M:%S" "${user_input}" "+%s"
fi
fi