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

bolt 使用示例

bolt 是一款高性能的key value 数据库,下面是它的使用示例:...

golang snappy 的使用场合

google 自家的 snappy 压缩优点是非常高的速度和合理的压缩率。压缩率比 gzip 小,CPU 占用小。...

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

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