time.FixedZone() Function in Golang With Examples
In Go language, time packages supplies functionality for determining as well as viewing time. The FixedZone() function in Go language is used to find a location that constantly uses the stated name of the zone and offset (i.e, seconds east of 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 FixedZone(name string, offset int) *Location
Here, “name” is the name of the zone, offset holds an integer and *Location is the pointer to the Location. Where “Location” forms the set of time offsets in use.
Return Value: It returns the location that constantly uses the stated zone name and offset.
Example 1:
package main
import (
"fmt"
"time"
)
func main() {
location := time .FixedZone( "UTC-7" , -7*50*50)
fmt.Println(location)
}
|
Output:
UTC-7
Here, the stated location is returned.
Example 2:
package main
import (
"fmt"
"time"
)
func main() {
location := time .FixedZone( "UTC-6" , -6*40*40)
tm := time .Date(2020, time .April, 6,
9, 55, 06, 0, location)
fmt.Println( tm )
}
|
Output:
2020-04-06 09:55:06 -0240 UTC-6
Here, at first FixedZone() method is called then Date() method is called with its parameters i.e, date, time, and location and then all these parameters are returned as output.
Last Updated :
19 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...