Skip to content

Instantly share code, notes, and snippets.

@srph
Last active August 10, 2018 22:07
Show Gist options
  • Save srph/6a8c3fa59213931b2ffc3dd59a0c88a3 to your computer and use it in GitHub Desktop.
Save srph/6a8c3fa59213931b2ffc3dd59a0c88a3 to your computer and use it in GitHub Desktop.
Go: Get today time.Time instance with given hour and minutes
package main
import (
"time"
)
func nowWithGivenTime(hour int, minutes int) (time.Time, error) {
today := time.Now()
l, err := time.LoadLocation("Local")
if err != nil {
return nil, err
}
return time.Date(today.Year(), today.Month(), today.Day(), hour, minutes, 0, 0, l), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment