time.Time.Local() Function in Golang with Examples
Last Updated :
19 Apr, 2020
In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Local() function in Go language is used to find “t” with the location that is set to local time. 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) Local() Time
Here, “t” is the stated time.
Return Value: It returns “t” along with the location that is set to local time.
Example 1:
package main
import "fmt"
import "time"
func main() {
t := time .Date(2019, 2, 11, 10,
03, 00, 00, time .UTC)
local := t.Local()
fmt.Printf( "%v\n" , local)
}
|
Output:
2019-02-11 10:03:00 +0000 UTC
Example 2:
package main
import "fmt"
import "time"
func main() {
location := time .FixedZone( "UTC-7" , -6*56*34)
t := time .Date(2019, 2, 11, 10, 03, 00, 00, location)
local := t.Local()
fmt.Printf( "%v\n" , local)
}
|
Output:
2019-02-11 13:13:24 +0000 UTC
Here, FixedZone() method is used in order to define the location parameter of the Date() method so the time in output is returned according to that location.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...