UTC秒轉日期date -d "1970-01-01 UTC 1270538720 seconds"Tue Apr 6 15:25:20 CST 2010日期轉UTC秒date -d "20100101 00:00:01" +%s 1262275201
converting unix timestamp to date$ date -d @1193144433Tue Oct 23 15:00:33 CEST 2007$ date --date "1970-01-01 1193144433 sec" "+%Y-%m-%d %T"2007-10-23 15:00:33$ date -d @1193144433 "+%Y-%m-%d %T"2007-10-23 15:00:33References:http://www.wains.be/index.php/2007/10/23/bash-converting-unix-timestamp-to-date/
計算花費時間#!/bin/bashfunction elapsed_time(){ s_time=$1 e_time=$2 elap_s=$((e_time-s_time)) ss=$((elap_s%60)) mm=$(((elap_s/60)%60)) hh=$((elap_s/3600)) printf "%02i:%02i:%02i" $hh $mm $ss}time1=$1time2=$2##echo $time1, $time2begin_time=`date -d "$time1" +%s`end_time=`date -d "$time2" +%s`##echo $begin_time, $end_timeecho `elapsed_time $begin_time $end_time`references:http://dragonspring.pixnet.net/blog/post/33073982-%5Blinux%5D%5Bshell%5D-%E9%97%9C%E6%96%BC'date'-%E6%87%89%E8%A9%B2%E7%9F%A5%E9%81%93%E7%9A%84%E4%BA%8B
張貼留言
3 則留言:
UTC秒轉日期
date -d "1970-01-01 UTC 1270538720 seconds"
Tue Apr 6 15:25:20 CST 2010
日期轉UTC秒
date -d "20100101 00:00:01" +%s 1262275201
converting unix timestamp to date
$ date -d @1193144433
Tue Oct 23 15:00:33 CEST 2007
$ date --date "1970-01-01 1193144433 sec" "+%Y-%m-%d %T"
2007-10-23 15:00:33
$ date -d @1193144433 "+%Y-%m-%d %T"
2007-10-23 15:00:33
References:
http://www.wains.be/index.php/2007/10/23/bash-converting-unix-timestamp-to-date/
計算花費時間
#!/bin/bash
function elapsed_time()
{
s_time=$1
e_time=$2
elap_s=$((e_time-s_time))
ss=$((elap_s%60))
mm=$(((elap_s/60)%60))
hh=$((elap_s/3600))
printf "%02i:%02i:%02i" $hh $mm $ss
}
time1=$1
time2=$2
##echo $time1, $time2
begin_time=`date -d "$time1" +%s`
end_time=`date -d "$time2" +%s`
##echo $begin_time, $end_time
echo `elapsed_time $begin_time $end_time`
references:
http://dragonspring.pixnet.net/blog/post/33073982-%5Blinux%5D%5Bshell%5D-%E9%97%9C%E6%96%BC'date'-%E6%87%89%E8%A9%B2%E7%9F%A5%E9%81%93%E7%9A%84%E4%BA%8B
張貼留言