How can I extract the value of my current local time offset?

后端 未结 3 1693
轮回少年
轮回少年 2021-02-19 00:22

I\'m struggling a bit trying to format and display some IBM mainframe TOD clock data. I want to format the data in both GMT and local time (as the default -- otherwise in the zo

3条回答
  •  不要未来只要你来
    2021-02-19 00:32

    You can use the Zone() method on the time type:

    package main
    
    import (
        "fmt"
        "time"
    )
    
    func main() {
        t := time.Now()
        zone, offset := t.Zone()
        fmt.Println(zone, offset)
    }
    

    Zone computes the time zone in effect at time t, returning the abbreviated name of the zone (such as "CET") and its offset in seconds east of UTC.

提交回复
热议问题