mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Log and kafka module
This commit is contained in:
parent
6c2beab9e5
commit
bb115b29fd
@ -12,42 +12,42 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TimeOffset = 8 * 3600 //8个小时的偏移量
|
TimeOffset = 8 * 3600 //8 hour offset
|
||||||
HalfOffset = 12 * 3600 //半天的小时偏移量
|
HalfOffset = 12 * 3600 //Half-day hourly offset
|
||||||
)
|
)
|
||||||
|
|
||||||
//获取当前的时间戳
|
//Get the current timestamp
|
||||||
func GetCurrentTimestamp() int64 {
|
func GetCurrentTimestamp() int64 {
|
||||||
return time.Now().Unix()
|
return time.Now().Unix()
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取当天0点的时间戳
|
//Get the timestamp at 0 o'clock of the day
|
||||||
func GetCurDayZeroTimestamp() int64 {
|
func GetCurDayZeroTimestamp() int64 {
|
||||||
timeStr := time.Now().Format("2006-01-02")
|
timeStr := time.Now().Format("2006-01-02")
|
||||||
t, _ := time.Parse("2006-01-02", timeStr)
|
t, _ := time.Parse("2006-01-02", timeStr)
|
||||||
return t.Unix() - TimeOffset
|
return t.Unix() - TimeOffset
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取当天12点的时间戳
|
//Get the timestamp at 12 o'clock on the day
|
||||||
func GetCurDayHalfTimestamp() int64 {
|
func GetCurDayHalfTimestamp() int64 {
|
||||||
return GetCurDayZeroTimestamp() + HalfOffset
|
return GetCurDayZeroTimestamp() + HalfOffset
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取当天0点格式化时间,格式为"2006-01-02_00-00-00"
|
//Get the formatted time at 0 o'clock of the day, the format is "2006-01-02_00-00-00"
|
||||||
func GetCurDayZeroTimeFormat() string {
|
func GetCurDayZeroTimeFormat() string {
|
||||||
return time.Unix(GetCurDayZeroTimestamp(), 0).Format("2006-01-02_15-04-05")
|
return time.Unix(GetCurDayZeroTimestamp(), 0).Format("2006-01-02_15-04-05")
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取当天12点格式化时间,格式为"2006-01-02_12-00-00"
|
//Get the formatted time at 12 o'clock of the day, the format is "2006-01-02_12-00-00"
|
||||||
func GetCurDayHalfTimeFormat() string {
|
func GetCurDayHalfTimeFormat() string {
|
||||||
return time.Unix(GetCurDayZeroTimestamp()+HalfOffset, 0).Format("2006-01-02_15-04-05")
|
return time.Unix(GetCurDayZeroTimestamp()+HalfOffset, 0).Format("2006-01-02_15-04-05")
|
||||||
}
|
}
|
||||||
func GetTimeStampByFormat(datetime string) string {
|
func GetTimeStampByFormat(datetime string) string {
|
||||||
timeLayout := "2006-01-02 15:04:05" //转化所需模板
|
timeLayout := "2006-01-02 15:04:05" //Template required for transformation
|
||||||
loc, _ := time.LoadLocation("Local") //获取时区
|
loc, _ := time.LoadLocation("Local") //Get time zone
|
||||||
tmp, _ := time.ParseInLocation(timeLayout, datetime, loc)
|
tmp, _ := time.ParseInLocation(timeLayout, datetime, loc)
|
||||||
timestamp := tmp.Unix() //转化为时间戳 类型是int64
|
timestamp := tmp.Unix() //Converted to timestamp type is int64
|
||||||
return strconv.FormatInt(timestamp, 10)
|
return strconv.FormatInt(timestamp, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user