fonchain-fiee/pkg/common/time.go

29 lines
575 B
Go
Raw Normal View History

2025-02-20 12:55:54 +00:00
package common
import (
"fmt"
"go.uber.org/zap"
"time"
)
// GetBeijingTime 获取当前时间的北京时间
func GetBeijingTime() string {
// 获取当前时间
now := time.Now()
// 设置北京时间的时区
beijing, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
zap.L().Error("获取北京时间时区失败", zap.Error(err))
return ""
}
// 将当前时间转换为北京时间
beijingTime := now.In(beijing).Format("2006-01-02 15:04:05")
// 打印北京时间
fmt.Println("当前北京时间是:", beijingTime)
return beijingTime
}