package main import "fmt" const ( // 定義每分鐘的秒數 SecondsPerMinute = 60 // 定義每小時的秒數 SecondsPerHour = SecondsPerMinute * 60 // 定義每天的秒數 SecondsPerDay = SecondsPerHour * 24 ) // 將傳入的“秒”解析為3種時間單位 func resolveTime(seconds int) (day int, hour int, minute int) { day = seconds / SecondsPerDay hour = seconds / SecondsPerHour minute = seconds / SecondsPerMinute return } func main() { // 將返回值作為列印引數 fmt.Println(resolveTime(1000)) // 只獲取訊息和分鐘 _, hour, minute := resolveTime(18000) fmt.Println(hour, minute) // 只獲取天 day, _, _ := resolveTime(90000) fmt.Println(day) }程式碼輸出結果:
0 0 16
5 300
1