简体   繁体   English

Bash将两个纪元时间转换为剩余时间

[英]Bash convert two Epoch times to remaining time

I'm trying to convert two Epoch (Unix timestamp) dates to human readable date (time left) 我正在尝试将两个纪元(Unix时间戳)日期转换为人类可读的日期(剩余时间)

AT=$(echo $RES | jq '.results[0].unixtime' | tr -d '"') # Returns unix time in JST.
NOW=$(TZ=":Asia/Tokyo" date +%s) # Returns current time in JST
DIFF=$(echo $AT-$NOW | bc)

As an example; 举个例子;

AT=1470038400
NOW=1470032871
DIFF=5529

How do I get the remaining time between the two in the following format: DAYd HOURh MINm SECs? 如何以以下格式获取两者之间的剩余时间:DAYD HOURh MINm SECs?

您可以尝试以下

printf "%dd %dh %dm %ds\n" $(( DIFF / (3600 * 24) ))  $(( (DIFF / 3600 ) % 24)) $(( (DIFF / 60) % 60)) $((DIFF % 60))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM