31 lines
630 B
Go
31 lines
630 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
now := time.Now()
|
|
fmt.Println("本地时间:", now)
|
|
|
|
// UTC 时区
|
|
utcLoc, _ := time.LoadLocation("UTC")
|
|
utcTime := now.In(utcLoc)
|
|
fmt.Println("UTC时间:", utcTime)
|
|
|
|
// 纽约时区
|
|
nyLoc, _ := time.LoadLocation("America/New_York")
|
|
nyTime := now.In(nyLoc)
|
|
fmt.Println("纽约时间:", nyTime)
|
|
|
|
// 时区偏移
|
|
_, offset := now.Zone()
|
|
fmt.Printf("本地时区偏移: %d 小时\n", offset/3600)
|
|
|
|
// 固定偏移时区(不依赖IANA数据)
|
|
estLoc := time.FixedZone("EST", -5*3600)
|
|
estTime := now.In(estLoc)
|
|
fmt.Println("EST时间 (FixedZone):", estTime)
|
|
}
|