Blockchain 如何将stub.getTextTimeStamp()转换为string类型?

Blockchain 如何将stub.getTextTimeStamp()转换为string类型?,blockchain,hyperledger-fabric,Blockchain,Hyperledger Fabric,我想将shim函数GetTxTimestamp()返回的事务时间戳转换为一个字符串,我可以将其作为文本响应打印出来。函数返回类型*timestamp.timestamp 我曾尝试将其类型转换为字符串[]字节,但均无效。指针似乎返回指向一个结构或包。事务时间戳是protobuf时间戳数据结构,自1970年以来包含秒和纳秒的整数。打印的一种方法是首先将其转换为golang Time数据结构,然后将其转换为string: time.Unix(timestamp.Seconds, int64(times

我想将shim函数GetTxTimestamp()返回的事务时间戳转换为一个字符串,我可以将其作为文本响应打印出来。函数返回类型*timestamp.timestamp


我曾尝试将其类型转换为字符串[]字节,但均无效。指针似乎返回指向一个结构或包。

事务时间戳是protobuf时间戳数据结构,自1970年以来包含秒和纳秒的整数。打印的一种方法是首先将其转换为golang Time数据结构,然后将其转换为string:

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

嗨,戴夫,谢谢你的快速回复!我尝试了您建议的方法,但当我这样尝试时,我遇到了一些编译错误:
txntmsp,errN:=stub.GetTxTimestamp()time1:=time.Unix(txntmsp.Seconds,int64(txntmsp.Nanos)).String()
这很有效。导入“时间”包后,识别出txntmsp.Seconds和txntmsp.nano值:
txntmsp,errN:=stub.GetTxTimestamp()\uz=errN time1:=time.Unix(txntmsp.Seconds,int64(txntmsp.nano)).String()