util

package
v0.0.0-...-cc3858d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 12 Imported by: 3

Documentation

Index

Constants

View Source
const (
	SecMs  = 1000
	MinMs  = 60 * SecMs
	HourMs = 60 * MinMs
	DayMs  = 24 * HourMs
	WeekMs = 7 * DayMs
)
View Source
const TimeFormat = "2006-01-02T15:04:05.000Z"

Variables

This section is empty.

Functions

func AddInt64

func AddInt64(a, b int64) (int64, bool)

func BoolTo

func BoolTo[T ~int | ~int8 | ~int16 | ~int32 | ~int64 |
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](b bool) T

func BytesAsStr

func BytesAsStr(b []byte) string

func GetFileSize

func GetFileSize(filePath string) (int64, error)

func GetLastResetTime

func GetLastResetTime(nowMs int64, resetHour int64) int64

GetLastResetTime 获取当前时间的上次跨天时间戳,nowMs为时间戳ms

func GetLastWeekResetTime

func GetLastWeekResetTime(nowMs int64, resetHour, resetWeekDay int64) int64

GetLastWeekResetTime 获取当前时间的上次跨周时间戳,nowMs为时间戳ms

func GetLocation

func GetLocation() *time.Location

func GetMessageFullName

func GetMessageFullName(msg proto.Message) string

GetMessageFullName 返回 game.CLoginSLG

func GetMessageName

func GetMessageName(msg proto.Message) string

GetMessageName 从 game.CLoginSLG 中获取 CLoginSLG

func GetNextDayResetTime

func GetNextDayResetTime(nowMs int64, resetHour int64) int64

GetNextDayResetTime 获取下次重置时间戳, nowMs为UTC时间戳

func GetNextWeekResetTime

func GetNextWeekResetTime(nowMs int64, resetHour, resetWeekDay int64) int64

GetNextWeekResetTime 获取下周重置时间(时刻), nowMs为UTC时间戳ms, 周天0和7都合法

func GetTimeOffset

func GetTimeOffset() time.Duration

GetTimeOffset 获取时间偏移量

func GetTimeZoneOffset

func GetTimeZoneOffset() int64

GetTimeZoneOffset 获取时区偏移量

func GetWeekday

func GetWeekday(nowMs int64) int64

GetWeekday 根据时间戳算出指定时区的周几,0是周天

func GoroutineID

func GoroutineID() int

func IsNewDayReset

func IsNewDayReset(before, after int64, resetHour int64) bool

IsNewDayReset 是否跨天某一小时, before\after为UTC时间戳ms, hour(0-23)

func IsWeekReset

func IsWeekReset(before, after int64, resetHour, resetWeekDay int64) bool

IsWeekReset 是否跨周before, after为UTC时间戳ms

func MakeMessageByFullName

func MakeMessageByFullName(fullName string) (proto.Message, error)

MakeMessageByFullName 根据proto全类名获取Message实例 game.CLoginSLG

func Ms2DateValue

func Ms2DateValue(t int64) int64

Ms2DateValue 从一个毫秒时间戳转换成年月日整型数值

func Ms2Time

func Ms2Time(ms int64) time.Time

Ms2Time ms时间戳转化为时间

func NewMessageByFullName

func NewMessageByFullName(fullName string, data []byte) (proto.Message, error)

NewMessageByFullName 根据proto全类名获取Message实例 game.CLoginSLG

func Now

func Now() time.Time

Now 获取当前时间

func NowMs

func NowMs() int64

NowMS 获取当前时间的毫秒时间戳

func OpenFile

func OpenFile(fullpath string) (*os.File, error)

func RotateLogFile

func RotateLogFile(filePath string) (*os.File, error)

func SetTimeOffset

func SetTimeOffset(newOffset time.Duration)

SetTimeOffset 设置时间偏移量,debug下修改时间

func SetTimezone

func SetTimezone(offsetSeconds int64)

SetTimezone 设置时区

func StrAsBytes

func StrAsBytes(s string) []byte

func Time2Ms

func Time2Ms(t time.Time) int64

Time2Ms 系统时间转化为 ms时间戳

func UpperFirst

func UpperFirst(str string) string

首字母大写

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL