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,040 points
79 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 16,450 points
92 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
343 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
52 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
30 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
36 views

© 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.