问题
How can I convert unix timestamp to hh:mm:ss:SSS (where SSS is milliseconds) in AWK.
For example:
echo 1456478048306 > time
cat time | awk ....... > readable_time_format
回答1:
You can use bash for that:
#!/bin/bash
ts="1456478048306"
unix_epoch=${ts:0:-3}
ms=${ts:((-3)):3}
echo "$(date -d@"${unix_epoch}" +%H:%M:%S):${ms}"
Btw, of course you can also use awk
. However awk does not allow to simplify things here a lot, the algorithm is more or less the same:
awk -v ts="1456478048306" '{
unix_epoch=substr(ts, 0, length(ts)-3)
ms=substr(ts, length(ts)-2, 3)
print strftime("%H:%M:%S", unix_epoch) ":" ms
}'
来源:https://stackoverflow.com/questions/35648508/convert-unix-timestamp-to-hhmmsssss-where-sss-is-milliseconds-in-awk