首次提交:初始化项目代码
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user