Author

Topic: How to convert time from Block header to Unix time ? (Read 2780 times)

member
Activity: 72
Merit: 10
Thanks

Quote
Sorry, I misunderstood.  I thought you were trying to parse block headers from "the blockchain", not web pages from blockchain.info.

I need to parse block headers of the signed blocks to test my hashing algorithm.

Already implemented SwapOrder  (BytesSwap) or Little Endian.

Implemented hex2decimal + decimal2binary

the issue is I get binary as a number, so number of bits is not correct.

Any idea for hex2bit in Javascript since
examples from the Internet failed to work (Firefox)

Should I add trailing 0s to  hex2bin ?

done in Python
Quote
header_bin = header_hex.decode('hex')

from
https://en.bitcoin.it/wiki/Block_hashing_algorithm
legendary
Activity: 3514
Merit: 4895

Time stamp in Blockchain from
http://blockchain.info/en/block-index/458660/00000000000000000fcea0d175785506f4681dc94d1fcf50deeda8082caf1543
is not in Unix Epoch Time.

Format is
Quote
Timestamp    2014-01-15 15:33:34
I need it converted into Unix epoch time

Sorry, I misunderstood.  I thought you were trying to parse block headers from "the blockchain", not web pages from blockchain.info.
member
Activity: 72
Merit: 10
btw

Javascript is not parsing

Time stamp from
http://blockchain.info/en/block-index/458660/00000000000000000fcea0d175785506f4681dc94d1fcf50deeda8082caf1543]http://blockchain.info/en/block-index/458660/00000000000000000fcea0d175785506f4681dc94d1fcf50deeda8082caf1543 [/url]

correctly

Quote
Date.parse("2014-01-15 15:33:34");

results in
Quote
NaN

ok

just tested
Date.parse("1970-01-01T00:00:00");

works fine

result
Quote
1332284400000

so I need to inject  "T"  character after first 10 characters in time stamp
from
http://blockchain.info

If you know other solution just let me know.
member
Activity: 72
Merit: 10
The time in the block header is already stored in Unix Epoch Time.

Perhaps this reference will be helpfull:

http://james.lab6.com/2012/01/12/bitcoin-285-bytes-that-changed-the-world/

Time stamp in Blockchain from
http://blockchain.info/en/block-index/458660/00000000000000000fcea0d175785506f4681dc94d1fcf50deeda8082caf1543
is not in Unix Epoch Time.


Format is
Quote
Timestamp    2014-01-15 15:33:34
I need it converted into Unix epoch time

What is a source of block headers coming with Time Stamp in Unix time ?
Can you give www address ?

What I need more are the following functions implemented in Javascript

hex2bin
SwapOrder  (for hex)
or LittleEndian

either in Javascript

got Hex2Bin function implementations in Javascript from
http://stackoverflow.com/questions/7695450/how-to-program-hex2bin-in-javascript

any better solutions suggested ?


none for hex swaporder Javascript yet

and finally I need to implement

Hex2Bin >  Hash  > Hex2Bin > Hash

to get Bitcoin Block header hashed


Still looking for Bitcoin Block Header hash implementation in Javascript ( no Java code)
to be run off-line.
legendary
Activity: 3514
Merit: 4895
The time in the block header is already stored in Unix Epoch Time.

Perhaps this reference will be helpfull:

http://james.lab6.com/2012/01/12/bitcoin-285-bytes-that-changed-the-world/
member
Activity: 72
Merit: 10
Hi,

How to convert time from Block header to Unix time ?

Time stamp in block header ( past hashed blocks) is in the following format

http://blockchain.info/en/block-index/458660/00000000000000000fcea0d175785506f4681dc94d1fcf50deeda8082caf1543

Timestamp    2014-01-15 15:33:34
I need it converted into Unix epoch time

as declared by
Block hashing algorithm
Time    Current timestamp as seconds since 1970-01-01T00:00 UTC    Every few seconds    4

in PHP
$time = littleEndian(1305998791);

Quote
header_hex = ("01000000" +
    "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
    "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
    "c7f5d74d" +
    "f2b9441a" +
     "42a14695")

fourth parameter  in Python code

file:///E:/Block%20hashing%20algorithm%20-%20Bitcoin.htm


or in plain C
http://pastebin.com/bW3fQA2a

Quote
// we are going to supply the block header with the values from the generation block 0
        header.version =        1;
        hex2bin(header.prev_block,              "0000000000000000000000000000000000000000000000000000000000000000");
        hex2bin(header.merkle_root,             "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
        header.timestamp =      1231006505;
        header.bits =           486604799;
        header.nonce =          2083236893;
       

I plan to read input parameters ( block headers ) from blocks hashed in the past to verify nonce
as a presentation to students.

Can you help me ?
Jump to: