time.Time.UTC() Function in Golang with Examples
In Go language, time packages supplies functionality for determining as well as viewing time. The Time.UTC() function in Go language is used to yield “t” with the location that is set to UTC. Moreover, this function is defined under the time package. Here, you need to import the “time” package in order to use these functions.
Syntax:
func (t Time) UTC() Time
Here, “t” is the stated time in UTC.
Return Value: It returns t with the location that is set to UTC.
Example 1:
// Golang program to illustrate the usage of// Time.UTC() function // Including main packagepackage main // Importing fmt and timeimport ( "fmt" "time") // Calling mainfunc main() { // Defining t for UTC method t := time.Date(2020, 11, 14, 11, 30, 32, 0, time.UTC) // Calling UTC method utc := t.UTC() // Prints output fmt.Printf("%v\n", utc)} |
Output:
2020-11-15 21:23:32 +0000 UTC
Example 2:
// Golang program to illustrate the usage of// Time.UTC() function // Including main packagepackage main // Importing fmt and timeimport ( "fmt" "time") // Calling mainfunc main() { // Defining t for UTC method t := time.Date(2020, 23, 40, 56, 70, 0, 0, time.UTC) // Calling UTC method utc := t.UTC() // Prints output fmt.Printf("%v\n", utc)} |
Output:
2021-12-12 09:10:00 +0000 UTC
Here, the time “t” stated in the above code have values that are out of usual range but they are normalized while conversion.

