how can i convert stub.GetTxTimestamp() to type string?

0 votes
I am using a shim function to return a timestamp and i want to convert the timestamp to string so that i can display it. the return type of the shim function is *timestamp.Timestamp. I tried to typecast the timestamp to string but it didnt work. How do i convert it to string?
Jul 5, 2018 in Blockchain by slayer
• 29,050 points
91 views

1 answer to this question.

0 votes

You can not directly convert the timestamp to string because go lang does not support it. To convert it to string,
you need to first convert the timestamp to golang Time data structure and then convert it to string.
You can use the following to do this:

time.Unix(timestamp.Seconds, int64(timestamp.Nanos)).String()

Ex: txntmsp,errN := stub.GetTxTimestamp() _ = errN time1 := time.Unix(txntmsp.Seconds, int64(txntmsp.Nanos)).String()

Note: you need to import the time package for this.

answered Jul 5, 2018 by digger
• 27,620 points

Related Questions In Blockchain

+1 vote
1 answer

Hyperledger - How can I use transaction certificates to enforce privacy?

The transaction certificates don't actually address privacy ...READ MORE

answered Apr 17, 2018 in Blockchain by Perry
• 17,010 points
104 views
+1 vote
1 answer
+1 vote
1 answer

How can I connect to the specified nodes using IPFS?

You can actually connect to the specific ...READ MORE

answered Apr 25, 2018 in Blockchain by Christine
• 15,790 points
367 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 27,620 points
55 views
+1 vote
1 answer
0 votes
1 answer

How i can use nodejs to watch transactions in bitcoin network?

you can use  const Socket = require('blockchain.info/Socket'); const mySocket ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 27,620 points
34 views
0 votes
1 answer

What encoding or data type can be used to get alphanumeric string in elixir?

Integers in Elixir are arbitrary precision integers, ...READ MORE

answered Aug 31, 2018 in Blockchain by digger
• 27,620 points
39 views