取巧方式(利用UTC时间,给出的秒数比较小(0-57599)可以用这个):
date -d"@3600" | awk '{print $4}'| awk -F":" '{$1=$1-8;OFS=":"}END{print $0}'
最好自己直接写脚本:
cat hours.sh
#!/bin/bash
hour=$(( $1/3600 ))
min=$(( ($1-${hour}*3600)/60 ))
sec=$(( $1-${hour}*3600-${min}*60 ))
echo ${hour}:${min}:${sec}
运行sh hours.sh 3702得1:1:42
自己写个小程序吧
#include
#include
#include
main()
{
int min=0,second=0,hour=0;
printf("请输入秒:");
scanf("%d",&second);
hour=second/3600;
min=second/60%60;
second%=60;
printf("%02d:%02d:%02d",hour,min,second);
return 0;
}
或者写成shell 脚本来做也行
shell脚本内容如下:
#!/bin/bash
min=0
second=0
hour=0
if [ $# -ne 1 ]
then
read -p "input second:" second
elif [ $# -eq 1 ]
then
second=$1
fi
hour=$[$second / 3600]
min=$[$[$second/60]%60]
#min=$[$second / 60]
#min=$[$min%60]
second=$[$second % 60];
printf "%02d:%02d:%02d" $hour $min $second
可以直接运行 也可以带一个参数(该参数即为待转化的秒)
写个shell脚本咯
#!/bin/bash
seconds=$1
hour=$(echo "${seconds}/3600" | bc)
minute=$(echo "${seconds}/60%60" | bc)
sec=$(echo "${seconds}%60" | bc)
printf "%02d:%02d:%02d" $hour $minute $sec
一行就可以搞定的:
echo "$((3600/3600)):$((3600%3600/60)):$((3600%3600%60))"