先說一下為什么寫這篇文章魄懂,因?yàn)槟壳皼]有一篇文章能讓我在Mac上成功執(zhí)行的腳步。
date -d
在Mac上提示以下錯誤:
date: option requires an argument -- d
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
以下時(shí)間戳都是以秒為單位
- 自定義日期時(shí)間轉(zhuǎn)時(shí)間戳
#/bin/sh
help="?"
if [ $# != 1 ] ; then
echo "參數(shù)為空额划,輸入的時(shí)間格式為:2022-01-16 15:26:11"
exit 0
elif [[ $1 = "?" ]]; then
echo "輸入的時(shí)間格式為:2022-01-16 15:26:11"
exit 0
fi
echo "北京時(shí)間:"$1
echo "時(shí)間戳:" $(date -j -f "%Y-%m-%d %H:%M:%S" "$1" +%s)
- 時(shí)間戳轉(zhuǎn)日期
#/bin/sh
echo "北京時(shí)間:"$(date -r $1)
echo "時(shí)間戳:"$1