我有以下Go代码:
now := time.Now().UTC().String()
log.Info("time is: " + now)
当它运行时,将输出:time is: 2020-08-21 10:34:43.3547088 +0000 UTC
我只想要HH:mm:ss中的时间精度,这样它将输出为:time is: 2020-08-21 10:34:43Z
我需要更改什么才能正确格式化时间?末尾必须包含“Z”。
最佳答案
您可以使用time format获得所需的时间。
func main() {
now := time.Now().UTC().Format("2006-01-02 15:04:05Z")
fmt.Println("time is: " + now)
}
在playground中
关于go - 使用Z精度格式化Go时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63521304/