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,370 points
1,492 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
• 26,740 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,100 points
875 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
1,997 views
0 votes
1 answer
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,433 views
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
• 26,740 points
979 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
• 26,740 points
1,262 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
• 26,740 points
778 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