1 Star 0 Fork 0

menuiis / gkit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
human.go 752 Bytes
一键复制 编辑 原始数据 按行查看 历史
SongZhibin97 提交于 2022-05-03 11:12 . feat:human duration
package timeout
import (
"fmt"
"time"
)
func HumanDurationFormat(stamp int64, designation ...time.Time) string {
designation = append(designation, time.Now())
now := designation[0].Sub(time.Unix(stamp, 0))
if now < time.Minute {
return "刚刚"
}
if now < time.Hour {
return fmt.Sprintf("%d分钟前", now/(time.Minute))
}
if now < 24*time.Hour {
return fmt.Sprintf("%d小时前", now/(time.Hour))
}
if now < 7*24*time.Hour {
return fmt.Sprintf("%d天前", now/(24*time.Hour))
}
if now < 30*7*24*time.Hour {
return fmt.Sprintf("%d周前", now/(7*24*time.Hour))
}
if now < 12*30*7*24*time.Hour {
return fmt.Sprintf("%d月前", now/(30*7*24*time.Hour))
}
return fmt.Sprintf("%d年前", now/(12*30*7*24*time.Hour))
}
Go
1
https://gitee.com/menciis/gkit.git
git@gitee.com:menciis/gkit.git
menciis
gkit
gkit
4f74120a101e

搜索帮助