时间戳转换

1、首先编辑tsToTime.sh,输入以下内容:

#!/bin/sh
cat $1 | while read line
do
  echo `date -d @$line "+%F %T"`
done

2、保存一个时间戳文件 ts.data,精确到秒(10位数), 查看前10行cat ts.data | head -n 10

1465837693
1465837714
1465837715
1465844972
1465844977
1465852150
1465852200
1465852207
1465852214
1465857432

3、运行代码,如下:

sh tsToTime.sh ts.data > time.data

4、得到结果time.data,查看前10行数据:cat time.data | head -n 10

2016-06-14 01:08:13
2016-06-14 01:08:34
2016-06-14 01:08:35
2016-06-14 03:09:32
2016-06-14 03:09:37
2016-06-14 05:09:10
2016-06-14 05:10:00
2016-06-14 05:10:07
2016-06-14 05:10:14
2016-06-14 06:37:12

author:刘帝伟
date:2016-06-14

results matching ""

    No results matching ""