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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate the usage of
// FixedZone() function
  
// Including main package
package main
  
// Importing fmt and time
import (
    "fmt"
    "time"
)
  
// Calling main
func main() {
  
    // Calling FixedZone method
    // with its parameter
    location := time.FixedZone("UTC-7", -7*50*50)
  
    // Prints location
    fmt.Println(location)
}

chevron_right


Output:

UTC-7

Here, the stated location is returned.

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate the usage of
// FixedZone() function
  
// Including main package
package main
  
// Importing fmt and time
import (
    "fmt"
    "time"
)
  
// Calling main
func main() {
  
    // Calling FixedZone
    // method with its parameters
    location := time.FixedZone("UTC-6", -6*40*40)
  
    // Calling Date method 
    // with all its parameters
    // that is date, time, and location
    tm := time.Date(2020, time.April, 6, 
                 9, 55, 06, 0, location)
  
    // Prints date, 
    // time and location
    fmt.Println(tm)
}

chevron_right


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.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.