Author

Topic: Parsing unix timestamp from CLI response with jq (Read 150 times)

jr. member
Activity: 53
Merit: 7
Not sure if you can use this but if you simply want to convert that to a readable date, you can use:

Code:
date -d @1440604784 +'%d.%m.%Y'

The output would be:

26.08.2015

Thank you. I used another approach, but your idea helped me to find the right solution for my issue.

e.g. (output truncated):
Code:
bitcoin-cli listtransactions | jq '.[].time |=(. | strftime("%Y-%m-%d"))'

Result:
Code:
{
  "txid": "5756ff16e2b9f881cd15b8a7e478b4899965f87f553b6210d0f8e5bf5be7df1d",
  "blockhash": "0000000000000000027d0985fef71cbc05a5ee5cdbdc4c6baf2307e6c5db8591",
  "blockheight": 371622,
  "confirmations": 160829,
  "time": "2015-08-26",
  "blocktime": 1440604784,
  "isCoinBase": true,
  "valueOut": 25.37726812,
  "size": 185
}
hero member
Activity: 1834
Merit: 759
i think you have to multiply the Unix time by 1000 because Unix time is in Seconds but the "date" takes milliseconds.
also the output should also contain time 08/26/2015 @ 3:59pm

The CLI output he quoted must be in milliseconds then, because I only took the blockTime variable, plugged it into the command, and formatted it the way he wanted. It looks like he only wanted the date so I cut out the time.
legendary
Activity: 2128
Merit: 1293
There is trouble abrewing
Not sure if you can use this but if you simply want to convert that to a readable date, you can use:

Code:
date -d @1440604784 +'%d.%m.%Y'

The output would be:

26.08.2015

i think you have to multiply the Unix time by 1000 because Unix time is in Seconds but the "date" takes milliseconds.
also the output should also contain time 08/26/2015 @ 3:59pm
hero member
Activity: 1834
Merit: 759
Not sure if you can use this but if you simply want to convert that to a readable date, you can use:

Code:
date -d @1440604784 +'%d.%m.%Y'

The output would be:

26.08.2015
jr. member
Activity: 53
Merit: 7
I would like to query data with the CLI and parse the response. I am using the terminal with jq for this.

{                                                                                                                                                   
  "txid": "5756ff16e2b9f881cd15b8a7e478b4899965f87f553b6210d0f8e5bf5be7df1d",                                                                                                                                                                                               
  "blockhash": "0000000000000000027d0985fef71cbc05a5ee5cdbdc4c6baf2307e6c5db8591",                                                                   
  "blockheight": 371622,                                                                                                                             
  "confirmations": 160829,                                                                                                                           
  "time": 1440604784,                                                                                                                               
  "blocktime": 1440604784,                                                                                                                           
  "isCoinBase": true,                                                                                                                               
  "valueOut": 25.37726812,                                                                                                                           
  "size": 185                                                                                                                                       
}

My goal is to change the unix timestamps to another format and pipe the result to another command.

So, the block time should be changed from this
  "blocktime": 1440604784,                                                                                                                           

to this
  "blocktime": "18.07.2018"
Jump to: