1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package util
- import "fmt"
- /*
- 时间常量
- */
- const (
- //定义每分钟的秒数
- SecondsPerMinute int64 = 60
- //定义每小时的秒数
- SecondsPerHour int64 = SecondsPerMinute * 60
- //定义每天的秒数
- SecondsPerDay int64 = SecondsPerHour * 24
- )
- /*
- 时间转换函数
- */
- func resolveTime(seconds int64) (day int64, hour int64, minute int64) {
- //每分钟秒数
- minute = seconds / SecondsPerMinute
- //每小时秒数
- hour = seconds / SecondsPerHour
- //每天秒数
- day = seconds / SecondsPerDay
- return
- }
- func TimeTransformation(unix int64) string {
- _, hour, _ := resolveTime(unix)
- now := ""
- if hour < 10 {
- now = fmt.Sprintf("0%d", hour)
- } else {
- now = fmt.Sprintf("%d", hour)
- }
- minute := (unix - (hour * SecondsPerHour)) / 60
- fmt.Println(minute, (hour * SecondsPerHour))
- if minute < 10 {
- now = fmt.Sprintf("%s:0%d", now, minute)
- } else {
- now = fmt.Sprintf("%s:%d", now, minute)
- }
- seconds := unix - (hour*SecondsPerHour + SecondsPerMinute*minute)
- if seconds < 10 {
- now = fmt.Sprintf("%s:0%d", now, seconds)
- } else {
- now = fmt.Sprintf("%s:%d", now, seconds)
- }
- return now
- }
|