How to convert timestamp to readable format in blockchain.info?

+1 vote

I need some help with Blockchain API timestamps. The timestamps from the JSON responses are not user readable. I need to parse this to a readable format to run some logical function based on time. 

The timestamp looks something like this:

"time": 1331300839,

I tried to do something like this:

var test = new Date(1331300839);
test.getFullYear();

This is not working. How can I convert the timestamp to a readable format?

Sep 3, 2018 in Blockchain by digger
• 26,550 points
878 views

3 answers to this question.

+2 votes
Best answer

You are talking about the block_time property of the block. The block_time is in Unix time format. A quick way to convert this without using any library is by running it through the date command.

Something like this:

$ date -d @1395103695
answered Apr 29 by Raghu

selected Apr 29 by Omkar

This works! The date is returned in the following format:

<Day> <Month> <Date> <Time> <Standards> <Year>

Hey. This is not working for me. I am using Mac OSX and this command is not working. Any alternatives for Mac OSX?

Try this for Mac:

$ date -j -f "%s" 1395103695
+2 votes

Try using the moment.js library. The code will look something like this:

var time = moment.unix(1331300839)

And then convert to parsed data to string using moment.toString():

time.toString()
// "Fri Sep 03 2018 10:23:19 GMT+0100"
answered Sep 3, 2018 by slayer
• 29,170 points
+2 votes

The date is not actually in a non-readable format, it's just in a different readable format. The data you mentioned in the question is the data in milliseconds. So, you can use that value and convert it into the data by multiplying it with 1000. Try something like this:

var test = new Date(1331300839*1000);
alert(test.getFullYear());
answered Sep 3, 2018 by Jonas Black

Related Questions In Blockchain

0 votes
1 answer

How to check payment in Blockchain.info wallet?

The above error is probably occurring due ...READ MORE

answered Aug 20, 2018 in Blockchain by Perry
• 17,020 points
96 views
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 123 views
0 votes
1 answer

In a Blockchain, how difficult is it to modify the third to last block?

Technically, it's not difficult at all, all ...READ MORE

answered Apr 20, 2018 in Blockchain by Christine
• 15,790 points
80 views
+1 vote
1 answer

How to store state data in Ethereum blockchain?

You won't have to overwrite the whole ...READ MORE

answered Apr 24, 2018 in Blockchain by Shashank
• 10,350 points
63 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,550 points
4,363 views
0 votes
1 answer
0 votes
1 answer

Python request module for bitcoin json rpc

This should work: #!/usr/bin/env python import getpass import json import requests ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,550 points
285 views
0 votes
1 answer

How to prevent the smart contract from being modified and deployed in the blockchain network?

To expand on Matthew's answer, each state ...READ MORE

answered Jul 5, 2018 in Blockchain by ariaholic
• 7,340 points
56 views
0 votes
1 answer

How to call function in one contract from another contract in private blockchain?

Please check whether you have byzantiumBlock: 0 in your ...READ MORE

answered Oct 1, 2018 in Blockchain by digger
• 26,550 points
55 views