I have one headache
with time. I have above code:
// ticker := time.NewTicker(time.Minute * 1)
ticker := time.NewTicker(time.Second * 1)
defer ticker.Stop()
// new version
for t := range ticker.C {
// get duration
go func() {
now := time.Now()
const layout = "2006-01-02 15:04:05"
endDateStr := fmt.Sprintf("%04d-%02d-%02d 23:45:00", now.Year(), now.Month(), now.Day())
endDate, _ := time.Parse(layout, endDateStr)
duration := endDate.Sub(now)
drHours := (duration.Minutes() - math.Mod(duration.Minutes(), 60)) / 60
drMinutes := math.Mod(duration.Minutes(), 60)
//fmt.Println(duration.Hours())
fmt.Println(now)
fmt.Println(endDate)
durStr := fmt.Sprintf("%d:%d:00", uint64(drHours), uint64(drMinutes))
fmt.Printf("duration: %s
", durStr)
}()
fmt.Println(t)
}
At my comp now
and endDate
have different time zone:
2015-11-12 10:33:53.9298552 +0500 UZT // now
2015-11-12 23:45:00 +0000 UTC // endDate
That's why get wrong duration. How can I set same time zone to both of them ? And a problem again, pay attantion when ticker tik first and second duration has differens 5 hour. Why those problems have occured. What am I doing wrong? Do you have any idea ? Made me happe any hint from you ?