0xBF
0xBF

0xBF

Go Cheatsheet - Print time in timezone

0xBF's photo
0xBF

Published on Aug 24, 2021

1 min read

1, LoadLocation

2, Call time.In method

package main

import (
    "log"
    "time"
)

func main() {
    t := time.Now()
    loc, err := time.LoadLocation("Asia/Shanghai")
    if err != nil {
        log.Fatalf("%s\n", err)
    }
    locTime := t.In(loc)
    log.Println(locTime.Format("01/02/2006 15:04:05"))
}

Run it:

08/25/2021 05:59:39
 
Share this