Convert specific UTC date time to PST, HST, MST and SGT
Example
package main
import (
"fmt"
"time"
)
func main() {
t, err := time.Parse("2006 01 02 15 04", "2015 11 11 16 50")
if err != nil {
fmt.Println(err)
}
fmt.Println(t)
loc, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
fmt.Println(err)
}
fmt.Println(loc)
t = t.In(loc)
fmt.Println(t.Format(time.RFC822))
loc, err = time.LoadLocation("Singapore")
if err != nil {
fmt.Println(err)
}
fmt.Println(loc)
t = t.In(loc)
fmt.Println(t.Format(time.RFC822))
loc, err = time.LoadLocation("US/Hawaii")
if err != nil {
fmt.Println(err)
}
fmt.Println(loc)
t = t.In(loc)
fmt.Println(t.Format(time.RFC822))
loc, err = time.LoadLocation("EST")
if err != nil {
fmt.Println(err)
}
fmt.Println(loc)
t = t.In(loc)
fmt.Println(t.Format(time.RFC822))
loc, err = time.LoadLocation("MST")
if err != nil {
fmt.Println(err)
}
fmt.Println(loc)
t = t.In(loc)
fmt.Println(t.Format(time.RFC822))
}
Output
2015-11-11 16:50:00 +0000 UTC
America/Los_Angeles
11 Nov 15 08:50 PST
Singapore
12 Nov 15 00:50 SGT
US/Hawaii
11 Nov 15 06:50 HST
EST
11 Nov 15 11:50 EST
MST
11 Nov 15 09:50 MST
Most Helpful This Week
Golang Functions Returning Multiple Values
How to declare and access pointer variable?
The return values of a function can be named in Golang
How to remove symbols from a string in Golang?
Replace any non-alphanumeric character sequences with a dash using Regex
How to check UPPERCASE characters in a string in Golang?
How can we reverse a simple string in Go?
How to get current IP form ipify.org ?
Get current date and time in various format in golang
How to check if a string contains a substring in Golang?