end=`date +%s -d "2011-11-28 15:55:52"`
echo $(($end-$start))
这个前提是你能拿到开始和结束时间字串的基础上的。
cat 日志文件 | awk '/^000/{
start=$2 " " $3
end=$4 " " $5
stm=mktime(gensub(/[:-]/, " ", "g", start))
etm=mktime(gensub(/[:-]/, " ", "g", end))
print $1 " - " etm-stm
}'
#include <stdio.h>#include <time.h>
int
main ()
{
struct tm tm, tm2
char buf[255]
time_t t1, t2
strptime ("Thu Feb 5 13:12:18 EST 2009", "%a %b %d %H:%M:%S EST %Y", &tm)
strptime ("Fri Feb 6 13:11:18 EST 2009", "%a %b %d %H:%M:%S EST %Y", &tm2)
t1 = mktime(&tm)
t2 = mktime(&tm2)
printf("TIME: %ld, %ld, %ld\n", t2, t1, t2-t1)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)