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 }