time.Location.String() Function in Golang With Examples
Last Updated :
21 Apr, 2020
In Go language, time packages supplies functionality for determining as well as viewing time. The Location.String() function in Go language is used to find an explanatory name stated for the data of time zone which is equivalent to the name parameter passes to the LoadLocation or FixedZone method. Moreover, this function is defined under the time package. Here, you need to import “time” package in order to use these functions.
Syntax:
func (l *Location) String() string
Here, “l” is the name of the location to be used, and *Location is the pointer to the Location. Where, “Location” forms the set of time offsets in use.
Return Value: It returns an explanatory name stated for the data of time zone.
Example 1:
package main
import (
"fmt"
"time"
)
func main() {
locat, error := time .LoadLocation( "Asia/Kolkata" )
if error != nil {
panic(error)
}
fmt.Println(locat.String())
}
|
Output:
Asia/Kolkata
Here, the IANA time zone of India is returned as there is no error.
Example 2:
package main
import (
"fmt"
"time"
)
func main() {
location := time .FixedZone( "UTC-7" , -7*50*50)
fmt.Println(location.String())
}
|
Output:
UTC-7
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...