Bitcoin Forum
November 19, 2018, 02:59:20 PM *
News: Latest Bitcoin Core release: 0.17.0 [Torrent].
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Parsing unix timestamp from CLI response with jq  (Read 36 times)
rpstatic
Jr. Member
*
Offline Offline

Activity: 56
Merit: 7


View Profile
July 18, 2018, 11:55:16 AM
 #1

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"

★ PRiVCY ➢ Own Your Privacy! ➢ Best privacy crypto-market! ★
✈✈✈[PoW/PoS]✅[Tor]✅[Airdrop]✈✈✈ (https://privcy.io/)
1542639560
Hero Member
*
Offline Offline

Posts: 1542639560

View Profile Personal Message (Offline)

Ignore
1542639560
Reply with quote  #2

1542639560
Report to moderator
1542639560
Hero Member
*
Offline Offline

Posts: 1542639560

View Profile Personal Message (Offline)

Ignore
1542639560
Reply with quote  #2

1542639560
Report to moderator
1542639560
Hero Member
*
Offline Offline

Posts: 1542639560

View Profile Personal Message (Offline)

Ignore
1542639560
Reply with quote  #2

1542639560
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
jseverson
Hero Member
*****
Offline Offline

Activity: 784
Merit: 646


View Profile
July 18, 2018, 02:38:21 PM
 #2

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

BrewMaster
Hero Member
*****
Offline Offline

Activity: 994
Merit: 656


There is trouble abrewing


View Profile
July 18, 2018, 03:20:26 PM
 #3

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

jseverson
Hero Member
*****
Offline Offline

Activity: 784
Merit: 646


View Profile
July 20, 2018, 02:34:31 AM
 #4

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.

rpstatic
Jr. Member
*
Offline Offline

Activity: 56
Merit: 7


View Profile
July 20, 2018, 07:50:28 AM
 #5

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
}

★ PRiVCY ➢ Own Your Privacy! ➢ Best privacy crypto-market! ★
✈✈✈[PoW/PoS]✅[Tor]✅[Airdrop]✈✈✈ (https://privcy.io/)
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!