123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package lib
- import (
- "strconv"
- )
- /*
- 时间常量
- */
- const (
- //定义每分钟的秒数
- SecondsPerMinute = 60
- //定义每小时的秒数
- SecondsPerHour = SecondsPerMinute * 60
- //定义每天的秒数
- SecondsPerDay = SecondsPerHour * 24
- )
- /*
- 时间转换函数
- */
- func resolveTime(seconds int) (day int, hour int, minute int, second int) {
- //秒
- second = seconds % 60
- //天
- day = seconds / SecondsPerDay
- seconds -= day * SecondsPerDay
- //时
- hour = seconds / SecondsPerHour
- seconds -= hour * SecondsPerHour
- //分
- minute = seconds / SecondsPerMinute
- seconds -= minute * SecondsPerHour
- return
- }
- func MinuteToDataTime(t int) string {
- str := ""
- day, hour, minute, second := resolveTime(t)
- if day > 0 {
- str += strconv.Itoa(day) + "天 "
- }
- if hour > 0 {
- str += strconv.Itoa(hour) + "小时 "
- }
- if minute > 0 {
- str += strconv.Itoa(minute) + "分钟 "
- }
- if second > 0 {
- str += strconv.Itoa(second) + "秒"
- }
- return str
- }
|