How to get the current timestamp in other timezones in Golang?

后端 未结 2 1309
太阳男子
太阳男子 2021-02-04 23:56

I need to get the current time in different time-zones.

Currently I know that we can do the following:

t := time.Now()
fmt.Println(\"Location:\", t.Loca         


        
相关标签:
2条回答
  • 2021-02-05 00:12

    No, that is the best way. You can create your custom Location using FixedZone and use that custom location.

    FixedZone returns a Location that always uses the given zone name and offset (seconds east of UTC).

    0 讨论(0)
  • 2021-02-05 00:13
    //init the loc
    loc, _ := time.LoadLocation("Asia/Shanghai")
    
    //set timezone,  
    now := time.Now().In(loc)
    
    0 讨论(0)
提交回复
热议问题