You can get the current time in the current timezone in Go using the 'time' package and the 'time.Now()' function. Here is an example:

package main

import (
    "fmt"
    "time"
)

func main() {
    loc, err := time.LoadLocation("") // load the current timezone
    if err != nil {
        fmt.Println(err)
        return
    }
    now := time.Now().In(loc)
    fmt.Println(now.Format("2006-01-02 15:04:05"))
}

In this example, we first load the current timezone using the 'time.LoadLocation("")' function. We then call the 'time.Now()' function to get the current time in the UTC timezone. We use the 'time.In()' method to convert the time to the current timezone. Finally, we use the 'time.Format()' method to format the time as a string in the format '2006-01-02 15:04:05'.

Golang: Get Current Time String in Local Timezone

原文地址: https://www.cveoy.top/t/topic/nVnq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录