fonchain-fiee/pkg/service/bundle/common/time.go

47 lines
1004 B
Go

package common
import (
"fmt"
"go.uber.org/zap"
"math/rand"
"time"
)
const source = "0123456789abcdefghijklmnopqrstUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
// 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
}
func GetZeroUuid() string {
id := time.Now().Format("20060102150405") + GetRandomstring(6)
result := "ZERO_" + id
return result
}
func GetRandomstring(length int) string {
rand.Seed(time.Now().UnixNano())
bytes := make([]byte, length)
for i := 0; i < length; i++ {
bytes[i] = source[rand.Intn(62)]
}
return string(bytes)
}