scripts/utool/number2d.sh
2023-06-05 23:04:30 +08:00

36 lines
1.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 自定义颜色显示
c_br='\e[1;31m' # bold red
c_bg='\e[1;32m' # bold green
c_by='\e[1;33m' # bold yellow
c_bb='\e[1;34m' # bold blue
c_bp='\e[1;35m' # bold purple
c_bc='\e[1;36m' # bold cyan
c_bir='\e[1;3;31m' # * bold italic red
c_big='\e[1;3;32m' # bold italic cyan
c_bib='\e[1;3;34m' # * bold italic cyan
c_bic='\e[1;3;36m' # bold italic cyan
c_e='\e[0m' # reset
number=$1
if [[ $number =~ ^[0-9]{1,11}$ ]]; then
date -d@$number +'%Y-%m-%d %H:%M:%S'
elif [[ $number =~ ^0[x|X][0-9a-fA-F]{1,9}$ ]]; then
hex=`printf "%d" $number`
date -d@$hex +'%Y-%m-%d %H:%M:%S'
elif [[ $number =~ ^[0-9a-fA-F]{1,9}$ ]]; then
hex=`printf "%d" '0x'$number`
date -d@$hex +'%Y-%m-%d %H:%M:%S'
else
echo -e "${c_br}请输入正确的十进制--11位以内或者十六进制数字--9位以内${c_e}"
echo -e " 十进制的时间戳 - 1678523385"
echo -e " 十六进制时间戳 - 0x640c3bf9/0X640C3BF9/0x640C3bf9/640c3bf9"
echo -e "${c_bb}有歧义时,使用'0x'或者'0X'来区分十进制和十六进制${c_e}"
exit 233
fi