shell时间戳与时间相互转换

#!/bin/bash
read -p "时间转化为时间戳请输入1,时间戳转化为时间请输入2:" time0
if [ $time0 -eq 1 ];then
  read -p "请输入你要转化的时间戳:" time1
  date -d @"$time1" "+%F %T" 2> /dev/null
fi
if [ $time0 -eq 2 ];then
  read -p "请输入你要转化的时间(xxxx-xx-xx xx:xx:xx):" time2
  date -d "$time2" +%s 2> /dev/null
fi
exit
if [ $time0 -eq 2 ];then
  echo "输入错误!!!"
  exit 
fi

 

posted @ 2019-05-17 17:04  Frank-hui  阅读(3887)  评论(0编辑  收藏  举报