I have time of the same day in minutes (ie, hours * 60 + minutes) as input ,need to convert it into time.Time
here is my attempt to do the same .
Example
Input: 780
Output : 2017-01-29 13:00:51.992871217 +0000 UTC
Code
func MinutesToTime(minutes int) time.Time {
t := time.Now().UTC() //may be cached
h, m, _ := t.Clock()
diff := minutes - (h*60 + m)
t = t.Add(time.Duration(diff) * time.Minute)
return t
}
Doubt
time
package exposes that might help me optimize thisPS The 59 sec err is acceptable as minute is my lowest granularity
package main
import (
"fmt"
"time"
)
func main() {
fmt.Print(MinutesToTime(780).UTC())
}
func MinutesToTime(m int64) time.Time {
return time.Unix(time.Now().Unix()/86400*86400+m*60, 0)
}
% go run test.go
2017-01-29 13:00:00 +0000 UTC%