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,740 points
10,638 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


Hope this helps!

Get your Blockchain certification today to learn more about this technology.

Thanks.

answered Apr 29, 2019 by Raghu

selected Apr 29, 2019 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,370 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 21, 2018 in Blockchain by Perry
• 17,100 points
1,214 views
0 votes
0 answers
0 votes
1 answer
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 1,567 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,740 points
45,218 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
885 views
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,740 points
2,361 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,922 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 6, 2018 in Blockchain by aryya
• 7,460 points
808 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,740 points
860 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP