Linux
這個 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'
會走多遠
echo $((DURSECS / 86400)):$(date +%T -d@$(( DURSECS % 86400 ))) 470:17:17:36
我懂了?
#!/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'