113.97.190.49 – – 1357574398 “GET http://www.test.com/index.htm HTTP/1.1” 200 14702 “http://www.test.com/” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5 .1; SV1)” TCP_HIT:NONE 1
以上是一条日志,第四个字段1357574398是时间戳,是从1970-01-01 00:00:00 UTC算起的秒数。
awk有内置的函数可以转换
#head access.log | awk '{print strftime("%y/%m/%d %T",$4)}'
13/01/07 00:00:00
13/01/07 00:00:02
13/01/07 00:00:03
13/01/07 00:00:03
13/01/07 00:00:20
13/01/07 00:00:20
13/01/07 00:00:24
13/01/07 00:00:25
13/01/07 00:00:25
13/01/07 00:00:00
在shell里可以这样转换
#date -d '1970-01-01 UTC 1357574397 seconds'
Mon Jan 7 23:59:57 CST 2013
标准时间转时间戳
现在的时间戳
#date +%s 1372039598
#date +%s | xargs -I {} date -d "1970-01-01 UTC {} seconds"
Mon Jun 24 10:07:33 CST 2013
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/2502.html