GolangNote

Golang笔记

go应用建议使用UTC 获取时间戳

Permalink

在获取时间时,建议使用 UTC ,让这成为习惯。方便日后转换方便,毕竟 go 里时区的转换还是挺麻烦。

Go: time UTC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package main

import (
  "fmt"
  "time"
)

func main() {
  fmt.Println("Hello, 世界")
  now := time.Now().UTC().Add(8 * time.Hour)
  //now = now.Add(8 * time.Hour)

  fmt.Println(now.Format("2006-01-02 15:04:05"))
  fmt.Println(now.Location())
  fmt.Println(now.Zone())
  fmt.Println(now.Unix())
}

本文网址: https://golangnote.com/topic/99.html 转摘请注明来源

Related articles

groupcache 使用入门

groupcache 是 memcached 作者 Brad Fitzpatrick 用 Go 语言编写的缓存及缓存过滤库,作为 memcached 许多场景下的替代版本。...

Write a Comment to "go应用建议使用UTC 获取时间戳"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.20 Processed in 0ms