Created
April 22, 2021 18:27
-
-
Save martinusso/8c674fb216c75715a7726ff3467f3411 to your computer and use it in GitHub Desktop.
Golang playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
t := time.Now().UTC() | |
fmt.Println("UTC") | |
fmt.Println(t) | |
fmt.Println(Format(t)) | |
l := "America/Fortaleza" | |
t1, _ := TimeIn(t, l) | |
fmt.Println(l) | |
fmt.Println(t1) | |
fmt.Println(Format(t1)) | |
} | |
func Format(t time.Time) string { | |
return t.Format("15:04:05") | |
} | |
func TimeIn(t time.Time, name string) (time.Time, error) { | |
loc, err := time.LoadLocation(name) | |
if err == nil { | |
t = t.In(loc) | |
} | |
return t, err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment