You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
620 B

2 months ago
package comment_service
import (
"fmt"
"strconv"
"time"
)
func GetTimeRecall(timestamp string, current int64) string {
timestampI64, _ := strconv.ParseInt(timestamp, 10, 64)
diff := current - timestampI64
if diff < 60 {
return "刚刚"
} else if diff < 60*60 {
minutes := diff / 60
return fmt.Sprint(minutes) + "分钟前"
} else if diff < 60*60*24 {
hours := diff / (60 * 60)
return fmt.Sprint(hours) + "小时前"
} else if diff < 60*60*24*14 {
days := diff / (60 * 60 * 24)
return fmt.Sprint(days) + "天前"
} else {
t := time.Unix(timestampI64, 0)
return t.Format("2006/01/02")
}
}