jq dates and unix timestamps

前端 未结 2 804
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 07:32

So I have a data with bunch of unix timestamp values (in milliseconds). Something like this:

{
    \"id\": \"f6922fd5-4f97-4113-820e-b45eba0ae236\",
    \"publis         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-02 08:26

    jq 1.5 has standard time-and-date functions such as strftime, as documented in the online manual. However support for TZ is extremely limited and/or unreliable, as illustrated here:

    $ echo $TZ
    
    $ jq -n '123 | strftime("%B %d %Y %I:%M%p %Z")'
    "January 01 1970 12:02AM EST"
    
    TZ='Asia/Kolkata' jq -n '123 | strftime("%B %d %Y %I:%M%p %Z")'
    "January 01 1970 12:02AM IST"
    

    strflocaltime

    If your jq has strflocaltime:

    TZ=Asia/Kolkata jq -n '123|strflocaltime("%Y-%m-%dT%H:%M:%S %Z")'
    "1970-01-01T05:32:03 IST"
    

提交回复
热议问题