datetime - 如何使用golang将UTC转换为印度本地时间

标签 datetime go time

提到下面的代码

 loc, _ := time.LoadLocation("Asia/Kolkata")
        now := time.Now().In(loc)
        fmt.Println("Location : ", loc, " Time : ", now)
        visit.Time = now

正在获取 UTC 时间,但我需要在我的数据存储中获取 IST

最佳答案

Go Playground ,这是按预期工作的。

About the 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/

相关文章:

go - 限制运行的并发任务数

r - 如何找到两个时间向量的不同元素?

date - 如何在 Swift 中解析/创建格式为小数秒 UTC 时区(ISO 8601、RFC 3339)的日期时间戳?

go - 如果 golang 文件依赖于 Asset 函数,如何构建它

google-app-engine - 使用 Memcache 在本地运行 Google App Engine Flex?

php - 如何在 PHP 中将日期 YYYY-MM-DD 转换为纪元

php - 商店时钟 - 根据商店营业时间显示 30 分钟倒计时

sql-server - 如何在 SQL 中从 DateTime 格式获取时间?

MySQL 和日期时间

c# - DateTime TextBox不为空,如何获取当前日期