Skip to content

Instantly share code, notes, and snippets.

@nidhi-canopas
Last active July 1, 2022 18:40
Show Gist options
  • Select an option

  • Save nidhi-canopas/75532ba3411e2fc9314df421ac416f42 to your computer and use it in GitHub Desktop.

Select an option

Save nidhi-canopas/75532ba3411e2fc9314df421ac416f42 to your computer and use it in GitHub Desktop.
func StartOfDay(t time.Time, timezone string) time.Time {
location, _ := time.LoadLocation(timezone)
year, month, day := t.In(location).Date()
fmt.Println("currentTime: ", t)
dayStartTime := time.Date(year, month, day, 0, 0, 0, 0, location)
fmt.Println("StartOfDay: ", dayStartTime)
return dayStartTime
}
/* get start of the day for given time */
StartOfDay(time.Now(), "Asia/Kolkata")
//output:
currentTime: 2022-07-01 22:47:16.791297534 +0530 IST m=+0.000346856
StartOfDay: 2022-07-01 00:00:00 +0530 IST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment