这个 shell 脚本(没有 bash)如何将秒显示为 DDD:HH:MM:SS?

这个 shell 脚本(没有 bash)如何将秒显示为 DDD:HH:MM:SS?
#!/bin/sh
INTERVAL=12
TOTAL=3388888
DURSECS=$(($TOTAL * $INTERVAL))
printf "\n$DURSECS seconds.\n"
printf "\nFormatted as DAYS:HOURS:MINUTES:SECONDS - DDD:HH:MM:SS - the total duration will be:\n"
# these do not do it
# TOTALTIMES=$(($DURSECS/(24*60*60), "ddd:hh:mm:ss"))
# printf "$TOTALTIMES"
# just need days here
date -u -d @${DURSECS} +"%T"

printf '\n\nTHE END\n'

答案1

会走多远

echo $((DURSECS / 86400)):$(date +%T -d@$(( DURSECS % 86400 )))
470:17:17:36

我懂了?

答案2

#!/bin/sh
INTERVAL=102
TOTAL=86401
DURSECS=$(($TOTAL * $INTERVAL))
printf "\n$DURSECS seconds.\n"
printf "\nFormatted as DAYS:HOURS:MINUTES:SECONDS - DDD:HH:MM:SS - the total duration will be:\n"
ddd=$(($DURSECS / 86400))
printf "$ddd:"
date -u -d @${DURSECS} +"%H:%M:%S"
printf '\n\nTHE END\n'

相关内容