LoginSignup
20
8

More than 5 years have passed since last update.

jq で エポックミリ秒を変換したい

Last updated at Posted at 2017-04-18

jq 便利だよね。何でも jq 使っちゃいます。
エポックミリ秒を jq だけで可視化出来たら素敵だなと思って調べました。

ですが、 jq では日付のパースを ISO8601 準拠のエポック秒までしか出来ません。
仕方ないので、1000 で割りましょう。

$ echo '1492377216630' | jq '(./1000|todate)' 
"2017-04-16T21:13:36Z"

1000割る時にあ、文字列だぞって怒られたら number に変換しましょう。

$ echo '1492377216630' | jq '(.|tonumber|./1000|todate)'

UTC → JST変換したい時の機能がないので、 計算する

$ echo '1492377216630' | jq '(.|tonumber|./1000|.+32400|todate)'
"2017-04-17T06:13:36Z"

jq 最高

20
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
8