Skip to content

Instantly share code, notes, and snippets.

@martinusso
Created April 22, 2021 18:27
Show Gist options
  • Save martinusso/8c674fb216c75715a7726ff3467f3411 to your computer and use it in GitHub Desktop.
Save martinusso/8c674fb216c75715a7726ff3467f3411 to your computer and use it in GitHub Desktop.
Golang playground
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