package main import ( "fmt" "time" ) func main() { t := time.Now().Local() fmt.Println("Local time:", t) fmt.Println("Timezone:", t.Location().String()) }
Local time: 2021-08-09 23:05:23.051808 -0400 EDT Timezone: EDT
package main import ( "fmt" "time" ) func main() { loc := time.Local t := time.Date(2021, time.August, 9, 12, 0, 0, 0, loc) fmt.Println(t) }
2021-08-09 12:00:00 -0400 EDTIn this example, we use time.Date() to create a new time value, passing in the year, month, day, hour, minute, second, nanosecond, and time zone Location. We pass in the time.Local pointer to use the system's local time zone. The resulting time value represents noon on August 9th, 2021 in the local time zone.