import ( "fmt" "time" ) func main() { t := time.Date(2022, time.August, 9, 14, 27, 0, 0, time.Local) r := t.Round(30 * time.Minute) fmt.Println(r) // Output: 2022-08-09 14:30:00 +0700 +07 }
import ( "fmt" "time" ) func main() { t := time.Date(2022, time.August, 9, 14, 27, 0, 0, time.Local) r := t.Round(time.Hour) fmt.Println(r) // Output: 2022-08-09 14:00:00 +0700 +07 }In both examples above, we import the "time" package and use the "Round" function to round the given time to the nearest multiple of the specified duration. The output is then printed to the console. Overall, "Round" is a useful function provided by the "time" package in Go that can help you round time-related data to the nearest specified duration.