【发布时间】:2019-06-24 12:12:04
【问题描述】:
我需要将 RFC3339 格式的任何给定时区转换为 RFC3339 格式的系统时间。但是对于像 IST 这样的少数时区,它会抛出错误并且时间仍然是 UTC。 对于转换哪个功能服务更好? time.parse 或 time.In.
我尝试将 UTC 转换为 IST,但失败了。
package main
import (
"fmt"
"time"
)
func main() {
//now time
now := time.Now()
fmt.Println("now ", now)
zone, _ := now.Zone()
fmt.Println("zone->", zone)
ll, llerr := time.LoadLocation(zone)
fmt.Println("Load Location", ll, llerr)
// Convert the given time to system based time zone
t, err := time.ParseInLocation(time.RFC3339, "2017-04-25T23:03:00Z", ll)
fmt.Println("t - parsein", t)
fmt.Println("err - parsein", err)
//fmt.Println("t2 - parse", t.In(ll))
}
错误:unknown time zone IST
预期:需要将任何时区转换为系统时区。
【问题讨论】: