收藏文章 楼主

shell日期时间和时间戳的转换

版块:shell   类型:普通   作者:小绿叶技术博客   查看:1301   回复:0   获赞:0   时间:2021-04-26 10:25:07

时间戳毫秒是16位数,秒是13位 (删除毫秒末尾后3位为秒)

1633317311766



#--- 打印字符串长度 ----#

a="123456789" ; echo ${a: 3: 4-2}   # echo ${ }  是计算函数,所以:4-2 等于2   如果为负数是倒数,需要添加空格指定

                                                         # 截取第3个字符后面的2个字符(不包含第3)

echo ${#a}                                        # 打印字符串长度




current=`date "+%Y-%m-%d %H:%M:%S"`        # 获取当前时间,例:2015-03-11 12:33:41     

  

timeStamp=`date -d "$current" +%s`                  # 将current转换为时间戳,精确到秒


currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000))

                                                                            # 将current转换为时间戳,精确到毫秒

echo $currentTimeStamp




date -d @1619059562  "+%Y%m%d%H%m"

#  将时间戳 1619059562  转换成 年月日时分  


date -d "2015-08-04 00:00:00" +%s  # 将时间转换成 时间戳



在线转换:https://tool.lu/timestamp/

提供企业建站服务,免费网防系统,提交信息登录 http://yundun.ddoss.cn 邮箱: proposal@ddoss.cn 
回复列表
默认   热门   正序   倒序

回复:shell日期时间和时间戳的转换

头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息