Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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 最高

sutoh
Like: PG/Ruby/Rails/Mac/GitHub/VB/JS/iOS/vim/Linux/AWS/PHP/Analytics/BigQuery/ Web♡Ruby
http://aquari.hatenablog.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした