I am storing the time as "02:00:00"
in my DB. But I want to show this time as my local timezone.
I tried to do this to convert the time from UTC to Asia/Jakarta
time:
package main
import (
"fmt"
"time"
)
func main() {
layout := "15:04:05"
inTimeStr := "02:00:00"
loc, _ := time.LoadLocation("Asia/Jakarta")
inTime, _ := time.Parse(layout, inTimeStr)
fmt.Println(inTime)
fmt.Println(inTime.In(loc).Format(layout))
}
I expected this to be 09:00:00
but surprisingly it was 09:07:12
.
I tried to change the year of the time to different values and I got different result. For me, it gave correct result if I set the year to 1970 or more.
Playground link: https://play.golang.org/p/o0nj15CRHud