douliao5942 2018-01-24 12:27
浏览 562
已采纳

如何使用golang将UTC转换为印度当地时间

Mentioning the code below

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

getting UTC time but i need to get IST in my datastore

  • 写回答

2条回答 默认 最新

  • doudou521125 2018-01-24 17:23
    关注

    In the Go Playground, this is working as expected.

    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

    Output:

    Location :  Asia/Kolkata  Time :  2009-11-11 04:30:00 +0530 IST
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化