[Pro-test] Conversión mutua de fecha, hora y marca de tiempo de Shell

Permítanme hablar sobre por qué escribí este artículo primero, porque actualmente no hay ningún artículo que me permita ejecutar con éxito scripts en Mac.

date -dMuestra el siguiente error en 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]

Las siguientes marcas de tiempo están en segundos

  • Convertir fecha y hora personalizada en marca de tiempo
#/bin/sh
help="?"
if [ $# != 1 ] ; then
  echo "参数为空,输入的时间格式为:2022-01-16 15:26:11"
  exit 0
elif [[ $1 = "?" ]]; then
  echo "输入的时间格式为:2022-01-16 15:26:11"
  exit 0
fi
echo "北京时间:"$1
echo "时间戳:" $(date -j -f "%Y-%m-%d %H:%M:%S" "$1" +%s)
  • Marca de tiempo hasta la fecha
#/bin/sh
echo "北京时间:"$(date -r $1)
echo "时间戳:"$1

Supongo que te gusta

Origin blog.csdn.net/stven_king/article/details/122524390
Recomendado
Clasificación