提到下面的代码
loc, _ := time.LoadLocation("Asia/Kolkata")
now := time.Now().In(loc)
fmt.Println("Location : ", loc, " Time : ", now)
visit.Time = now
正在获取 UTC 时间,但我需要在我的数据存储中获取 IST
最佳答案
在Go Playground ,这是按预期工作的。
The Go Playground is a web service that runs on golang.org's servers. The service receives a Go program, compiles, links, and runs the program inside a sandbox, then returns the output.
There are limitations to the programs that can be run in the playground:
In the playground the time begins at 2009-11-10 23:00:00 UTC (determining the significance of this date is an exercise for the reader). This makes it easier to cache programs by giving them deterministic output.
The article "Inside the Go Playground" describes how the playground is implemented.
package main
import (
"fmt"
"time"
)
func main() {
loc, _ := time.LoadLocation("Asia/Kolkata")
now := time.Now().In(loc)
fmt.Println("Location : ", loc, " Time : ", now)
}
Playground :https://play.golang.org/p/l8t3BnQATg7
输出:
Location : Asia/Kolkata Time : 2009-11-11 04:30:00 +0530 IST
关于datetime - 如何使用golang将UTC转换为印度本地时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48422482/