How to convert timestamp to readable format in

+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);

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

Sep 3, 2018 in Blockchain by digger
• 27,620 points

3 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+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():

// "Fri Sep 03 2018 10:23:19 GMT+0100"
answered Sep 3, 2018 by slayer
• 29,040 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);
answered Sep 3, 2018 by Jonas Black

Related Questions In Blockchain

0 votes
1 answer

How to check payment in wallet?

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

answered Aug 20, 2018 in Blockchain by Perry
• 16,450 points
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 64 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
+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,330 points
+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
• 27,620 points
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
• 27,620 points
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,320 points
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
• 27,620 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.