Initial commit
This commit is contained in:
33
server/framework/utils/time.go
Normal file
33
server/framework/utils/time.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package Utils
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TimeFormat(unix int) (string, string) {
|
||||
timeInt := time.Unix(int64(unix), 0)
|
||||
return timeInt.Format("2006年01月02日"), timeInt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
func DateFormat(times int) string {
|
||||
createTime := time.Unix(int64(times), 0)
|
||||
now := time.Now().Unix()
|
||||
|
||||
difTime := now - int64(times)
|
||||
|
||||
str := ""
|
||||
if difTime < 60 {
|
||||
str = "刚刚"
|
||||
} else if difTime < 3600 {
|
||||
M := difTime / 60
|
||||
str = strconv.Itoa(int(M)) + "分钟前"
|
||||
} else if difTime < 3600*24 {
|
||||
H := difTime / 3600
|
||||
str = strconv.Itoa(int(H)) + "小时前"
|
||||
} else {
|
||||
str = createTime.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
Reference in New Issue
Block a user